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

commit r17-5447-gbf99f4e35204f77c132dcb7fa958e590ace6306f
Author: Wesley Lewis <[email protected]>
Date:   Sun Oct 11 08:09:20 2026 +0000

    gccrs: check for curly/square braces in an attribute
    
    Fixes Rust-GCC/gccrs#4938
    
    gcc/rust/ChangeLog:
    
            * checks/errors/rust-attribute-checker.cc
            (AttributeChecker::visit): Added check.
    
    gcc/testsuite/ChangeLog:
    
            * rust/compile/wrong_meta_list_delims.rs: Added new test.
    
    Signed-off-by: Wesley Lewis <[email protected]>

Diff:
---
 gcc/rust/checks/errors/rust-attribute-checker.cc   | 26 ++++++++++++++++++++--
 .../rust/compile/wrong_meta_list_delims.rs         | 12 ++++++++++
 2 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/gcc/rust/checks/errors/rust-attribute-checker.cc 
b/gcc/rust/checks/errors/rust-attribute-checker.cc
index 4580aa256142..5a98cf883b0e 100644
--- a/gcc/rust/checks/errors/rust-attribute-checker.cc
+++ b/gcc/rust/checks/errors/rust-attribute-checker.cc
@@ -94,8 +94,30 @@ AttributeChecker::visit (AST::Token &)
 {}
 
 void
-AttributeChecker::visit (AST::DelimTokenTree &)
-{}
+AttributeChecker::visit (AST::DelimTokenTree &ttree)
+{
+  // Checking if the DelimTokenTree contains '('
+  // or something else. If something else, then error
+  const auto &token_stream = ttree.to_token_stream ();
+  for (auto &token : token_stream)
+    {
+      switch (token.get ()->get_id ())
+       {
+       case TokenId::LEFT_PAREN:
+         // correct case
+         break;
+       case TokenId::LEFT_CURLY:
+       case TokenId::LEFT_SQUARE:
+         rust_error_at (token.get ()->get_locus (),
+                        "wrong meta list delimiters");
+         rust_inform (token.get ()->get_locus (),
+                      "the delimiters should be %<(%> and %<)%>");
+         break;
+       default:
+         break;
+       }
+    }
+}
 
 void
 AttributeChecker::visit (AST::IdentifierExpr &)
diff --git a/gcc/testsuite/rust/compile/wrong_meta_list_delims.rs 
b/gcc/testsuite/rust/compile/wrong_meta_list_delims.rs
new file mode 100644
index 000000000000..ddef3b87d8a5
--- /dev/null
+++ b/gcc/testsuite/rust/compile/wrong_meta_list_delims.rs
@@ -0,0 +1,12 @@
+// { dg-additional-options "-frust-compat-version=1.84" }
+
+// check if the delimiters used for attributes is `(` and not either of `{` 
`[` 
+
+#![feature(no_core)]
+#![no_core]
+
+#[allow{unused}] // { dg-error "wrong meta list delimiters" "" { target *-*-* 
} }
+struct A {}
+
+#[allow[unused]] // { dg-error "wrong meta list delimiters" "" { target *-*-* 
} }
+struct B {}
\ No newline at end of file

Reply via email to