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
This commit is contained in:
Michael Goulet 2025-03-06 12:22:15 -05:00 committed by GitHub
commit 34d273b4bf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 29 additions and 0 deletions

View file

@ -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.

View file

@ -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() {}