diff options
| author | Michael Goulet <michael@errs.io> | 2025-03-06 12:22:15 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-06 12:22:15 -0500 |
| commit | 34d273b4bf3412794e3f5accf6866b61b17b78cf (patch) | |
| tree | 0caed31a2ea81e6b5c757a25ae1f6bfdebad67a5 | |
| parent | 91175bd932ea78cf4ae21bd0f11df3146da93293 (diff) | |
| parent | 41dd80aeaa706c169df62bdf16033b61b914cb87 (diff) | |
| download | rust-34d273b4bf3412794e3f5accf6866b61b17b78cf.tar.gz rust-34d273b4bf3412794e3f5accf6866b61b17b78cf.zip | |
Rollup merge of #137758 - jdonszelmann:fix-137662, r=nnethercote
fix usage of ty decl macro fragments in attributes See the test case. Due to one missing code path (and also the changes in #137517), using $ty or other specific fragments as part of an attr wouldn't work. $tt used to work since it wouldn't be parsed anywhere along the way. Closes #137662
| -rw-r--r-- | compiler/rustc_attr_parsing/src/parser.rs | 9 | ||||
| -rw-r--r-- | tests/ui/attributes/decl_macro_ty_in_attr_macro.rs | 20 |
2 files changed, 29 insertions, 0 deletions
diff --git a/compiler/rustc_attr_parsing/src/parser.rs b/compiler/rustc_attr_parsing/src/parser.rs index 96fc9d7d9ac..f0cce26f4e2 100644 --- a/compiler/rustc_attr_parsing/src/parser.rs +++ b/compiler/rustc_attr_parsing/src/parser.rs @@ -473,6 +473,15 @@ impl<'a> MetaItemListParserContext<'a> { { self.inside_delimiters.next(); return Some(MetaItemOrLitParser::Lit(lit)); + } else if let Some(TokenTree::Delimited(.., Delimiter::Invisible(_), inner_tokens)) = + self.inside_delimiters.peek() + { + self.inside_delimiters.next(); + return MetaItemListParserContext { + inside_delimiters: inner_tokens.iter().peekable(), + dcx: self.dcx, + } + .next(); } // or a path. diff --git a/tests/ui/attributes/decl_macro_ty_in_attr_macro.rs b/tests/ui/attributes/decl_macro_ty_in_attr_macro.rs new file mode 100644 index 00000000000..e633c08be3a --- /dev/null +++ b/tests/ui/attributes/decl_macro_ty_in_attr_macro.rs @@ -0,0 +1,20 @@ +// tests for #137662: using a ty or (or most other) fragment inside an attr macro wouldn't work +// because of a missing code path. With $repr: tt it did work. +//@ check-pass + +macro_rules! foo { + { + $repr:ty + } => { + #[repr($repr)] + pub enum Foo { + Bar = 0i32, + } + } +} + +foo! { + i32 +} + +fn main() {} |
