[COMMITTED 016/101] gccrs: Reject auto traits with generic parameters
arthur.cohen@embecosm.com
arthur.cohen@embecosm.com
Tue Jan 30 12:06:32 GMT 2024
From: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Generic parameters are not allowed on auto traits, the compiler should
emit an error.
gcc/rust/ChangeLog:
* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add
check for generics on auto traits.
* checks/errors/rust-ast-validation.h: Add visit function prototype.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
---
gcc/rust/checks/errors/rust-ast-validation.cc | 14 ++++++++++++++
gcc/rust/checks/errors/rust-ast-validation.h | 1 +
2 files changed, 15 insertions(+)
diff --git a/gcc/rust/checks/errors/rust-ast-validation.cc b/gcc/rust/checks/errors/rust-ast-validation.cc
index f6ce45eacca..37d3668a9e0 100644
--- a/gcc/rust/checks/errors/rust-ast-validation.cc
+++ b/gcc/rust/checks/errors/rust-ast-validation.cc
@@ -96,4 +96,18 @@ ASTValidation::visit (AST::Function &function)
AST::ContextualASTVisitor::visit (function);
}
+void
+ASTValidation::visit (AST::Trait &trait)
+{
+ if (trait.is_auto ())
+ {
+ if (trait.has_generics ())
+ rust_error_at (trait.get_generic_params ()[0]->get_locus (),
+ ErrorCode::E0567,
+ "auto traits cannot have generic parameters");
+ }
+
+ AST::ContextualASTVisitor::visit (trait);
+}
+
} // namespace Rust
diff --git a/gcc/rust/checks/errors/rust-ast-validation.h b/gcc/rust/checks/errors/rust-ast-validation.h
index 44995eb1fbc..49133ee0c3d 100644
--- a/gcc/rust/checks/errors/rust-ast-validation.h
+++ b/gcc/rust/checks/errors/rust-ast-validation.h
@@ -38,6 +38,7 @@ public:
virtual void visit (AST::LoopLabel &label);
virtual void visit (AST::ExternalFunctionItem &item);
virtual void visit (AST::Function &function);
+ virtual void visit (AST::Trait &trait);
};
} // namespace Rust
--
2.42.1
More information about the Gcc-rust
mailing list