Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix usage of ty decl macro fragments in attributes #137758

Merged
merged 1 commit into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {}
Loading