Skip to content

Commit 34d273b

Browse files
Rollup merge of rust-lang#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 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
2 parents 91175bd + 41dd80a commit 34d273b

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

compiler/rustc_attr_parsing/src/parser.rs

+9
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,15 @@ impl<'a> MetaItemListParserContext<'a> {
473473
{
474474
self.inside_delimiters.next();
475475
return Some(MetaItemOrLitParser::Lit(lit));
476+
} else if let Some(TokenTree::Delimited(.., Delimiter::Invisible(_), inner_tokens)) =
477+
self.inside_delimiters.peek()
478+
{
479+
self.inside_delimiters.next();
480+
return MetaItemListParserContext {
481+
inside_delimiters: inner_tokens.iter().peekable(),
482+
dcx: self.dcx,
483+
}
484+
.next();
476485
}
477486

478487
// or a path.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// tests for #137662: using a ty or (or most other) fragment inside an attr macro wouldn't work
2+
// because of a missing code path. With $repr: tt it did work.
3+
//@ check-pass
4+
5+
macro_rules! foo {
6+
{
7+
$repr:ty
8+
} => {
9+
#[repr($repr)]
10+
pub enum Foo {
11+
Bar = 0i32,
12+
}
13+
}
14+
}
15+
16+
foo! {
17+
i32
18+
}
19+
20+
fn main() {}

0 commit comments

Comments
 (0)