[gcc r16-8229] gccrs: feat: Implement `no_core` feature gate check

Arthur Cohen cohenarthur@gcc.gnu.org
Fri Mar 20 17:25:52 GMT 2026


https://gcc.gnu.org/g:3753033a3ad629eacfb4fd1fd537e6938893482a

commit r16-8229-g3753033a3ad629eacfb4fd1fd537e6938893482a
Author: Mohamed Ali <mohmedali1462005@gmail.com>
Date:   Thu Mar 5 12:02:51 2026 +0200

    gccrs: feat: Implement `no_core` feature gate check
    
    The compiler was accepting `#![no_core]` without requiring
    `#![feature(no_core)]`, silently treating an unstable attribute
    as stable.  Gate it via check_no_core_attribute, consistent with
    how other experimental attributes are handled.
    
    Fixes: Rust-GCC#4461
    
    gcc/rust/ChangeLog:
    
            * checks/errors/feature/rust-feature-gate.cc (FeatureGate::visit): Call check_no_core_attri.
            * checks/errors/feature/rust-feature-gate.h: Declare method check_no_core_attri.
    
    gcc/testsuite/ChangeLog:
    
            * rust/compile/match-scope.rs: Fix test.
            * rust/compile/no_core_feature_gate.rs: New test.
    
    Signed-off-by: Mohamed Ali <mohmedali1462005@gmail.com>

Diff:
---
 gcc/rust/checks/errors/feature/rust-feature-gate.cc | 13 +++++++++++++
 gcc/rust/checks/errors/feature/rust-feature-gate.h  |  1 +
 gcc/testsuite/rust/compile/match-scope.rs           |  1 +
 gcc/testsuite/rust/compile/no_core_feature_gate.rs  |  3 +++
 4 files changed, 18 insertions(+)

diff --git a/gcc/rust/checks/errors/feature/rust-feature-gate.cc b/gcc/rust/checks/errors/feature/rust-feature-gate.cc
index 14471c4f7f0f..7e21059776b6 100644
--- a/gcc/rust/checks/errors/feature/rust-feature-gate.cc
+++ b/gcc/rust/checks/errors/feature/rust-feature-gate.cc
@@ -63,6 +63,7 @@ FeatureGate::visit (AST::Crate &crate)
       rust_error_at (locus, ErrorCode::E0635, "unknown feature %qs",
 		     feature.c_str ());
     }
+  check_no_core_attribute (crate.inner_attrs);
 }
 
 void
@@ -108,6 +109,18 @@ FeatureGate::visit (AST::ExternBlock &block)
   AST::DefaultASTVisitor::visit (block);
 }
 
+void
+FeatureGate::check_no_core_attribute (
+  const std::vector<AST::Attribute> &attributes)
+{
+  for (const AST::Attribute &attr : attributes)
+    {
+      if (attr.get_path ().as_string () == Values::Attributes::NO_CORE)
+	gate (Feature::Name::NO_CORE, attr.get_locus (),
+	      "no_core is experimental");
+    }
+}
+
 void
 FeatureGate::check_rustc_attri (const std::vector<AST::Attribute> &attributes)
 {
diff --git a/gcc/rust/checks/errors/feature/rust-feature-gate.h b/gcc/rust/checks/errors/feature/rust-feature-gate.h
index 21997bcae0e6..0675777e0f58 100644
--- a/gcc/rust/checks/errors/feature/rust-feature-gate.h
+++ b/gcc/rust/checks/errors/feature/rust-feature-gate.h
@@ -54,6 +54,7 @@ public:
 
 private:
   void gate (Feature::Name name, location_t loc, const std::string &error_msg);
+  void check_no_core_attribute (const std::vector<AST::Attribute> &attributes);
   void check_rustc_attri (const std::vector<AST::Attribute> &attributes);
   void
   check_may_dangle_attribute (const std::vector<AST::Attribute> &attributes);
diff --git a/gcc/testsuite/rust/compile/match-scope.rs b/gcc/testsuite/rust/compile/match-scope.rs
index da7c84132baa..86cc1f9b0fc7 100644
--- a/gcc/testsuite/rust/compile/match-scope.rs
+++ b/gcc/testsuite/rust/compile/match-scope.rs
@@ -1,3 +1,4 @@
+#![feature(no_core)]
 #![no_core]
 
 pub fn main() -> i32 {
diff --git a/gcc/testsuite/rust/compile/no_core_feature_gate.rs b/gcc/testsuite/rust/compile/no_core_feature_gate.rs
new file mode 100644
index 000000000000..38be54050a1f
--- /dev/null
+++ b/gcc/testsuite/rust/compile/no_core_feature_gate.rs
@@ -0,0 +1,3 @@
+#![no_core] // { dg-error "no_core is experimental" }
+
+fn main() {}


More information about the Gcc-cvs mailing list