From: Mohamed Ali <[email protected]>

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 <[email protected]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.


Commit on github: 
https://github.com/Rust-GCC/gccrs/commit/9b1e540f3e5d1a3486e58c9df3c18907294c33d7

The commit has been mentioned in the following pull-request(s):
 - https://github.com/Rust-GCC/gccrs/pull/4462

 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(+)
 create mode 100644 gcc/testsuite/rust/compile/no_core_feature_gate.rs

diff --git a/gcc/rust/checks/errors/feature/rust-feature-gate.cc 
b/gcc/rust/checks/errors/feature/rust-feature-gate.cc
index 14471c4f7..7e2105977 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 21997bcae..0675777e0 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 da7c84132..86cc1f9b0 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 000000000..38be54050
--- /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() {}

base-commit: aafa6b453870cedfdacb3032fd052b2aa6ee08b4
-- 
2.53.0

Reply via email to