]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Detect failure to match an ident metavariable
authorOwen Avery <powerboat9.gamer@gmail.com>
Sun, 10 Aug 2025 15:56:54 +0000 (11:56 -0400)
committerArthur Cohen <arthur.cohen@embecosm.com>
Thu, 30 Oct 2025 19:58:38 +0000 (20:58 +0100)
Fixes https://github.com/Rust-GCC/gccrs/issues/4054

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h
(Parser::parse_identifier_or_keyword_token): Record error on
failure.

gcc/testsuite/ChangeLog:

* rust/compile/macros/mbe/macro-issue4054.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/macro-issue4054.rs [new file with mode: 0644]

index 5d7c5309fb0d0acf9c2dc6fd69133b478aef9915..38bf85e49d8ba9ca2405b6787241e09d74c07b62 100644 (file)
@@ -1053,6 +1053,7 @@ Parser<ManagedTokenSource>::parse_identifier_or_keyword_token ()
     }
   else
     {
+      add_error (Error (t->get_locus (), "expected keyword or identifier"));
       return nullptr;
     }
 }
diff --git a/gcc/testsuite/rust/compile/macros/mbe/macro-issue4054.rs b/gcc/testsuite/rust/compile/macros/mbe/macro-issue4054.rs
new file mode 100644 (file)
index 0000000..6dcab23
--- /dev/null
@@ -0,0 +1,14 @@
+#[allow(path_statements)]
+
+macro_rules! array_impl_default {
+    {$t:ident} => {
+        $t;
+        array_impl_default!{}
+    };
+    {} => {}
+}
+
+pub fn foo() {
+    let x = 12;
+    array_impl_default! {x}
+}