diff options
author | benjamin.thos <benjamin.thos@epita.fr> | 2024-09-11 14:31:20 +0000 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2025-03-19 15:32:10 +0100 |
commit | 5aedc53315387276070e36a5dac4e768f7540cf2 (patch) | |
tree | a19efc6ed65f0157f9fb21587218ec140722a150 /gcc | |
parent | e620a86e4d7591eb446df828506da76c070d1eb9 (diff) | |
download | gcc-5aedc53315387276070e36a5dac4e768f7540cf2.zip gcc-5aedc53315387276070e36a5dac4e768f7540cf2.tar.gz gcc-5aedc53315387276070e36a5dac4e768f7540cf2.tar.bz2 |
gccrs: Emit error on auto-traits
Throw an error when auto-traits used without feature attribute.
gcc/rust/ChangeLog:
* checks/errors/rust-feature-gate.cc (FeatureGate::visit): Emit error
on trait when auto field member true.
* checks/errors/rust-feature-gate.h: add prototype of trait visitor.
* checks/errors/rust-feature.cc (Feature::create): add
optin_builtin_traits in match of feature.
gcc/testsuite/ChangeLog:
* rust/compile/auto_trait_super_trait.rs: Add feature attribute.
* rust/compile/generic_auto_trait.rs: likewise.
* rust/compile/auto_trait.rs: add test for error without
feature attribute
Signed-off-by: benjamin.thos <benjamin.thos@epita.fr>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/checks/errors/rust-feature-gate.cc | 9 | ||||
-rw-r--r-- | gcc/rust/checks/errors/rust-feature-gate.h | 1 | ||||
-rw-r--r-- | gcc/rust/checks/errors/rust-feature.cc | 3 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/auto_trait.rs | 1 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/auto_trait_super_trait.rs | 1 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/generic_auto_trait.rs | 1 |
6 files changed, 16 insertions, 0 deletions
diff --git a/gcc/rust/checks/errors/rust-feature-gate.cc b/gcc/rust/checks/errors/rust-feature-gate.cc index 4ab614e..f3daa61 100644 --- a/gcc/rust/checks/errors/rust-feature-gate.cc +++ b/gcc/rust/checks/errors/rust-feature-gate.cc @@ -174,6 +174,15 @@ FeatureGate::visit (AST::TraitImpl &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) { gate ( diff --git a/gcc/rust/checks/errors/rust-feature-gate.h b/gcc/rust/checks/errors/rust-feature-gate.h index 7ffb6ef..f1011e5 100644 --- a/gcc/rust/checks/errors/rust-feature-gate.h +++ b/gcc/rust/checks/errors/rust-feature-gate.h @@ -42,6 +42,7 @@ public: 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 6900bb8..25af46c 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 0000000..47bd119 --- /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 1080afb..06746e9 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 ae6a51d..a0a414c 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<G> {} // { dg-error "auto traits cannot have generic parameters .E0567." "" { target *-*-* } .-1 } |