forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#78677 - Aaron1011:fix/capture-inner-attrs, r=…
…petrochenkov Use reparsed `TokenStream` if we captured any inner attributes Fixes rust-lang#78675 We now bail out of `prepend_attrs` if we ended up capturing any inner attributes (which can happen in several places, due to token capturing for `macro_rules!` arguments.
- Loading branch information
Showing
4 changed files
with
132 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/test/ui/proc-macro/issue-78675-captured-inner-attrs.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// check-pass | ||
// edition:2018 | ||
// compile-flags: -Z span-debug | ||
// aux-build:test-macros.rs | ||
|
||
#![no_std] // Don't load unnecessary hygiene information from std | ||
extern crate std; | ||
|
||
#[macro_use] extern crate test_macros; | ||
|
||
macro_rules! foo {( | ||
#[fake_attr] | ||
$item:item | ||
) => ( | ||
$item | ||
)} | ||
|
||
macro_rules! outer {($item:item) => ( | ||
print_bang! { // Identity proc-macro | ||
foo! { | ||
#[fake_attr] | ||
$item | ||
} | ||
} | ||
)} | ||
outer! { | ||
mod bar { | ||
//! Foo | ||
} | ||
} | ||
|
||
fn main() {} |
86 changes: 86 additions & 0 deletions
86
src/test/ui/proc-macro/issue-78675-captured-inner-attrs.stdout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
PRINT-BANG INPUT (DISPLAY): foo ! { #[fake_attr] mod bar { | ||
#![doc = r" Foo"] | ||
} } | ||
PRINT-BANG INPUT (DEBUG): TokenStream [ | ||
Ident { | ||
ident: "foo", | ||
span: $DIR/issue-78675-captured-inner-attrs.rs:20:9: 20:12 (#4), | ||
}, | ||
Punct { | ||
ch: '!', | ||
spacing: Alone, | ||
span: $DIR/issue-78675-captured-inner-attrs.rs:20:12: 20:13 (#4), | ||
}, | ||
Group { | ||
delimiter: Brace, | ||
stream: TokenStream [ | ||
Punct { | ||
ch: '#', | ||
spacing: Alone, | ||
span: $DIR/issue-78675-captured-inner-attrs.rs:21:13: 21:14 (#4), | ||
}, | ||
Group { | ||
delimiter: Bracket, | ||
stream: TokenStream [ | ||
Ident { | ||
ident: "fake_attr", | ||
span: $DIR/issue-78675-captured-inner-attrs.rs:21:15: 21:24 (#4), | ||
}, | ||
], | ||
span: $DIR/issue-78675-captured-inner-attrs.rs:21:14: 21:25 (#4), | ||
}, | ||
Group { | ||
delimiter: None, | ||
stream: TokenStream [ | ||
Ident { | ||
ident: "mod", | ||
span: $DIR/issue-78675-captured-inner-attrs.rs:22:13: 22:18 (#4), | ||
}, | ||
Ident { | ||
ident: "bar", | ||
span: $DIR/issue-78675-captured-inner-attrs.rs:22:13: 22:18 (#4), | ||
}, | ||
Group { | ||
delimiter: Brace, | ||
stream: TokenStream [ | ||
Punct { | ||
ch: '#', | ||
spacing: Joint, | ||
span: $DIR/issue-78675-captured-inner-attrs.rs:22:13: 22:18 (#4), | ||
}, | ||
Punct { | ||
ch: '!', | ||
spacing: Alone, | ||
span: $DIR/issue-78675-captured-inner-attrs.rs:22:13: 22:18 (#4), | ||
}, | ||
Group { | ||
delimiter: Bracket, | ||
stream: TokenStream [ | ||
Ident { | ||
ident: "doc", | ||
span: $DIR/issue-78675-captured-inner-attrs.rs:22:13: 22:18 (#4), | ||
}, | ||
Punct { | ||
ch: '=', | ||
spacing: Alone, | ||
span: $DIR/issue-78675-captured-inner-attrs.rs:22:13: 22:18 (#4), | ||
}, | ||
Literal { | ||
kind: StrRaw(0), | ||
symbol: " Foo", | ||
suffix: None, | ||
span: $DIR/issue-78675-captured-inner-attrs.rs:22:13: 22:18 (#4), | ||
}, | ||
], | ||
span: $DIR/issue-78675-captured-inner-attrs.rs:22:13: 22:18 (#4), | ||
}, | ||
], | ||
span: $DIR/issue-78675-captured-inner-attrs.rs:22:13: 22:18 (#4), | ||
}, | ||
], | ||
span: $DIR/issue-78675-captured-inner-attrs.rs:22:13: 22:18 (#4), | ||
}, | ||
], | ||
span: $DIR/issue-78675-captured-inner-attrs.rs:20:14: 23:10 (#4), | ||
}, | ||
] |