https://gcc.gnu.org/g:c7c4074d3ead555f69e7be9f1f6509800f563396
commit r16-4781-gc7c4074d3ead555f69e7be9f1f6509800f563396 Author: Owen Avery <[email protected]> Date: Sun Aug 10 11:56:54 2025 -0400 gccrs: Detect failure to match an ident metavariable 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 <[email protected]> Diff: --- gcc/rust/parse/rust-parse-impl.h | 1 + gcc/testsuite/rust/compile/macros/mbe/macro-issue4054.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 5d7c5309fb0d..38bf85e49d8b 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -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 index 000000000000..6dcab23289fa --- /dev/null +++ b/gcc/testsuite/rust/compile/macros/mbe/macro-issue4054.rs @@ -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} +}
