diff --git a/gcc/rust/checks/errors/feature/rust-feature-gate.cc b/gcc/rust/checks/errors/feature/rust-feature-gate.cc index 14471c4f7f0..7e21059776b 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 &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 &attributes) { diff --git a/gcc/rust/checks/errors/feature/rust-feature-gate.h b/gcc/rust/checks/errors/feature/rust-feature-gate.h index 21997bcae0e..0675777e0f5 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 &attributes); void check_rustc_attri (const std::vector &attributes); void check_may_dangle_attribute (const std::vector &attributes); diff --git a/gcc/testsuite/rust/compile/match-scope.rs b/gcc/testsuite/rust/compile/match-scope.rs index da7c84132ba..86cc1f9b0fc 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 00000000000..38be54050a1 --- /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() {}