public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-8544] gccrs: Add check for associated items on auto traits
@ 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:685491f232459f6182899893a7326582e153f11e

commit r14-8544-g685491f232459f6182899893a7326582e153f11e
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date:   Mon Nov 20 14:59:56 2023 +0100

    gccrs: Add check for associated items on auto traits
    
    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>

Diff:
---
 gcc/rust/checks/errors/rust-ast-validation.cc    |  7 +++++++
 gcc/rust/parse/rust-parse-impl.h                 | 12 ------------
 gcc/testsuite/rust/compile/auto_trait_invalid.rs |  5 +++--
 3 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/gcc/rust/checks/errors/rust-ast-validation.cc b/gcc/rust/checks/errors/rust-ast-validation.cc
index aeae6035db8f..673290959f4b 100644
--- a/gcc/rust/checks/errors/rust-ast-validation.cc
+++ b/gcc/rust/checks/errors/rust-ast-validation.cc
@@ -109,6 +109,13 @@ ASTValidation::visit (AST::Trait &trait)
 	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);
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index de17412c3b68..45c72e495c27 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -4989,18 +4989,6 @@ Parser<ManagedTokenSource>::parse_trait (AST::Visibility vis,
       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,
diff --git a/gcc/testsuite/rust/compile/auto_trait_invalid.rs b/gcc/testsuite/rust/compile/auto_trait_invalid.rs
index 66e45531f5d8..3be2acbb53b6 100644
--- a/gcc/testsuite/rust/compile/auto_trait_invalid.rs
+++ b/gcc/testsuite/rust/compile/auto_trait_invalid.rs
@@ -2,7 +2,9 @@
 
 #![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" }
@@ -13,4 +15,3 @@ unsafe auto trait Invalid { // { dg-error "auto traits cannot have associated it
 
     const BAR: i32 = 15; // { dg-message "remove this item" }
 }
-// { dg-error "failed to parse item in crate" "" {target *-*-* } .+1 }

^ 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-8544] gccrs: Add check for associated items on auto traits 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).