Reject rust code with associated items on auto traits.
gcc/rust/ChangeLog:
* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add auto
trait associated item check in AST validation pass.
* parse/rust-parse-impl.h: Remove old error emission done during
parsing pass.
gcc/testsuite/ChangeLog:
* rust/compile/auto_trait_invalid.rs: Update old test with updated
error message.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
rust_error_at (trait.get_type_param_bounds ()[0]->get_locus (),
ErrorCode::E0568,
"auto traits cannot have super traits");
+ if (trait.has_trait_items ())
+ {
+ rust_error_at (trait.get_identifier ().get_locus (), ErrorCode::E0380,
+ "auto traits cannot have methods or associated items");
+ for (const auto &item : trait.get_trait_items ())
+ Error::Hint (item->get_locus (), "remove this item").emit ();
+ }
}
AST::ContextualASTVisitor::visit (trait);
return nullptr;
}
- if (is_auto_trait && !trait_items.empty ())
- {
- add_error (Error (locus, ErrorCode::E0380,
- "auto traits cannot have associated items"));
-
- // FIXME: unsure if this should be done at parsing time or not
- for (const auto &item : trait_items)
- add_error (Error::Hint (item->get_locus (), "remove this item"));
-
- return nullptr;
- }
-
trait_items.shrink_to_fit ();
return std::unique_ptr<AST::Trait> (
new AST::Trait (std::move (ident), is_unsafe, is_auto_trait,
#![feature(optin_builtin_traits)]
-unsafe auto trait Invalid { // { dg-error "auto traits cannot have associated items" }
+auto trait Invalid {
+ // { dg-error "auto traits cannot have methods or associated items" "" { target *-*-* } .-1 }
+
fn foo(); // { dg-message "remove this item" }
fn bar() {} // { dg-message "remove this item" }
const BAR: i32 = 15; // { dg-message "remove this item" }
}
-// { dg-error "failed to parse item in crate" "" {target *-*-* } .+1 }