Skip to content

Commit

Permalink
Rollup merge of rust-lang#137758 - jdonszelmann:fix-137662, r=nnether…
Browse files Browse the repository at this point in the history
…cote

fix usage of ty decl macro fragments in attributes

See the test case. Due to one missing code path (and also the changes in rust-lang#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 rust-lang#137662
  • Loading branch information
compiler-errors authored Mar 6, 2025
2 parents 2479067 + 41dd80a commit 7d5a65f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
9 changes: 9 additions & 0 deletions compiler/rustc_attr_parsing/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 20 additions & 0 deletions tests/ui/attributes/decl_macro_ty_in_attr_macro.rs
Original file line number Diff line number Diff line change
@@ -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() {}

0 comments on commit 7d5a65f

Please sign in to comment.