From: Owen Avery Date: Sun, 10 Aug 2025 15:56:54 +0000 (-0400) Subject: gccrs: Detect failure to match an ident metavariable X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c7c4074d3ead555f69e7be9f1f6509800f563396;p=thirdparty%2Fgcc.git 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 --- diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 5d7c5309fb0..38bf85e49d8 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -1053,6 +1053,7 @@ Parser::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 00000000000..6dcab23289f --- /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} +}