Skip to content

Commit

Permalink
Emit error on auto-traits
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Kamiinarii authored and P-E-P committed Sep 11, 2024
1 parent 9941d6f commit f2e0322
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions gcc/rust/checks/errors/rust-feature-gate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions gcc/rust/checks/errors/rust-feature-gate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions gcc/rust/checks/errors/rust-feature.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
}
Expand Down
1 change: 1 addition & 0 deletions gcc/testsuite/rust/compile/auto_trait.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
auto trait Valid {} // { dg-error "auto traits are experimental and possibly buggy" }
1 change: 1 addition & 0 deletions gcc/testsuite/rust/compile/auto_trait_super_trait.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![feature(optin_builtin_traits)]
trait Cold {}

auto trait IsCool: Cold {}
Expand Down
1 change: 1 addition & 0 deletions gcc/testsuite/rust/compile/generic_auto_trait.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#![feature(optin_builtin_traits)]
auto trait IsCooler<G> {}
// { dg-error "auto traits cannot have generic parameters .E0567." "" { target *-*-* } .-1 }

0 comments on commit f2e0322

Please sign in to comment.