]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix Attr metavariable binding
authorOwen Avery <powerboat9.gamer@gmail.com>
Sat, 10 May 2025 02:17:55 +0000 (22:17 -0400)
committerPhilip Herron <philip.herron@embecosm.com>
Tue, 13 May 2025 09:29:13 +0000 (09:29 +0000)
gcc/rust/ChangeLog:

* parse/rust-parse-impl.h
(Parser::parse_attr_input): Handle more delimeter tokens and the
END_OF_FILE token.
(Parser::skip_after_end_attribute): Handle the END_OF_FILE
token.

gcc/testsuite/ChangeLog:

* rust/compile/macros/mbe/meta-param.rs: New test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/parse/rust-parse-impl.h
gcc/testsuite/rust/compile/macros/mbe/meta-param.rs [new file with mode: 0644]

index e165998e2cb91185aa84fb8f56361daa92eaeee1..bbe75ad88c277f47c3631ac651e19eaafae2bc0b 100644 (file)
@@ -877,7 +877,10 @@ Parser<ManagedTokenSource>::parse_attr_input ()
        return attr_input_lit;
       }
       break;
+    case RIGHT_PAREN:
     case RIGHT_SQUARE:
+    case RIGHT_CURLY:
+    case END_OF_FILE:
       // means AttrInput is missing, which is allowed
       return nullptr;
     default:
@@ -11911,7 +11914,7 @@ Parser<ManagedTokenSource>::skip_after_end_attribute ()
 {
   const_TokenPtr t = lexer.peek_token ();
 
-  while (t->get_id () != RIGHT_SQUARE)
+  while (t->get_id () != RIGHT_SQUARE && t->get_id () != END_OF_FILE)
     {
       lexer.skip_token ();
       t = lexer.peek_token ();
diff --git a/gcc/testsuite/rust/compile/macros/mbe/meta-param.rs b/gcc/testsuite/rust/compile/macros/mbe/meta-param.rs
new file mode 100644 (file)
index 0000000..ed6e100
--- /dev/null
@@ -0,0 +1,7 @@
+macro_rules! foo {
+    ($x:meta) => {0}
+}
+
+pub fn main() -> i32 {
+    foo!(Clone)
+}