diff --git a/gcc/rust/checks/errors/rust-feature-gate.cc b/gcc/rust/checks/errors/rust-feature-gate.cc index 2b2c44a8ea8c..5f07d22f1ac1 100644 --- a/gcc/rust/checks/errors/rust-feature-gate.cc +++ b/gcc/rust/checks/errors/rust-feature-gate.cc @@ -173,6 +173,15 @@ FeatureGate::visit (AST::TraitImpl &impl) AST::DefaultASTVisitor::visit (impl); } +void +FeatureGate::visit (AST::Trait &trait) +{ + if (trait.is_auto ()) + gate (Feature::Name::AUTO_TRAITS, trait.get_locus (), + "auto traits are experimental and possibly buggy"); + AST::DefaultASTVisitor::visit (trait); +} + void FeatureGate::visit (AST::BoxExpr &expr) { diff --git a/gcc/rust/checks/errors/rust-feature-gate.h b/gcc/rust/checks/errors/rust-feature-gate.h index f8a9db78d201..2d63f4cfdbe1 100644 --- a/gcc/rust/checks/errors/rust-feature-gate.h +++ b/gcc/rust/checks/errors/rust-feature-gate.h @@ -42,6 +42,7 @@ class FeatureGate : public AST::DefaultASTVisitor void visit (AST::UseTreeGlob &use_tree) override; void visit (AST::Function &function) override; void visit (AST::TraitImpl &impl) override; + void visit (AST::Trait &trait) override; void visit (AST::ExternalTypeItem &item) override; void visit (AST::ExternBlock &block) override; void visit (AST::MacroRulesDefinition &rules_def) override; diff --git a/gcc/rust/checks/errors/rust-feature.cc b/gcc/rust/checks/errors/rust-feature.cc index 3fab5e5aedcc..04872613d114 100644 --- a/gcc/rust/checks/errors/rust-feature.cc +++ b/gcc/rust/checks/errors/rust-feature.cc @@ -55,6 +55,9 @@ Feature::create (Feature::Name f) "1.11.0", 37854); case Feature::Name::PRELUDE_IMPORT: return Feature (f, Feature::State::ACTIVE, "prelude_import", "1.0.0"); + case Feature::Name::AUTO_TRAITS: + return Feature (f, Feature::State::ACTIVE, "optin_builtin_traits", + "1.0.0", 13231); default: rust_unreachable (); } diff --git a/gcc/testsuite/rust/compile/auto_trait.rs b/gcc/testsuite/rust/compile/auto_trait.rs new file mode 100644 index 000000000000..47bd119ba36b --- /dev/null +++ b/gcc/testsuite/rust/compile/auto_trait.rs @@ -0,0 +1 @@ +auto trait Valid {} // { dg-error "auto traits are experimental and possibly buggy" } diff --git a/gcc/testsuite/rust/compile/auto_trait_super_trait.rs b/gcc/testsuite/rust/compile/auto_trait_super_trait.rs index 1080afb5124d..06746e914979 100644 --- a/gcc/testsuite/rust/compile/auto_trait_super_trait.rs +++ b/gcc/testsuite/rust/compile/auto_trait_super_trait.rs @@ -1,3 +1,4 @@ +#![feature(optin_builtin_traits)] trait Cold {} auto trait IsCool: Cold {} diff --git a/gcc/testsuite/rust/compile/generic_auto_trait.rs b/gcc/testsuite/rust/compile/generic_auto_trait.rs index ae6a51d0244c..a0a414cdbbd4 100644 --- a/gcc/testsuite/rust/compile/generic_auto_trait.rs +++ b/gcc/testsuite/rust/compile/generic_auto_trait.rs @@ -1,2 +1,3 @@ +#![feature(optin_builtin_traits)] auto trait IsCooler {} // { dg-error "auto traits cannot have generic parameters .E0567." "" { target *-*-* } .-1 }