public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-8540] gccrs: Reject auto traits with generic parameters
@ 2024-01-30 11:58 Arthur Cohen
  0 siblings, 0 replies; only message in thread
From: Arthur Cohen @ 2024-01-30 11:58 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:b1b744fc467a3cee4af0f85a8d8fb2b68f68b2d3

commit r14-8540-gb1b744fc467a3cee4af0f85a8d8fb2b68f68b2d3
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date:   Mon Nov 20 13:43:48 2023 +0100

    gccrs: Reject auto traits with generic parameters
    
    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>

Diff:
---
 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 f6ce45eaccab..37d3668a9e04 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 44995eb1fbce..49133ee0c3d8 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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-01-30 11:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-30 11:58 [gcc r14-8540] gccrs: Reject auto traits with generic parameters Arthur Cohen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).