diff options
| author | bors <bors@rust-lang.org> | 2018-12-28 02:54:14 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-12-28 02:54:14 +0000 |
| commit | e8ca35e63dda82a8b5fa8eb72cf3e490a5794a46 (patch) | |
| tree | 190e1b7ce725d1fdfaf44e49c34a9465d558ac0a /src/test | |
| parent | f8caa321c7c7214a6c5415e4b3694e65b4ff73a7 (diff) | |
| parent | e40d7d9643b810b2bc62f279e1d6f4ad68a35bc2 (diff) | |
| download | rust-e8ca35e63dda82a8b5fa8eb72cf3e490a5794a46.tar.gz rust-e8ca35e63dda82a8b5fa8eb72cf3e490a5794a46.zip | |
Auto merge of #57155 - petrochenkov:dcrate3, r=dtolnay
Resolve `$crate`s for pretty-printing at more appropriate time Doing it in `BuildReducedGraphVisitor` wasn't a good idea, identifiers wasn't actually visited half of the time. As a result some `$crate`s weren't resolved and were therefore pretty-printed as `$crate` literally, which turns into two tokens during re-parsing of the pretty-printed text. Now we are visiting and resolving `$crate` identifiers in an item right before sending that item to a proc macro attribute or derive. Fixes https://github.com/rust-lang/rust/issues/57089
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/ui/proc-macro/auxiliary/dollar-crate.rs | 7 | ||||
| -rw-r--r-- | src/test/ui/proc-macro/dollar-crate-issue-57089.rs | 26 | ||||
| -rw-r--r-- | src/test/ui/proc-macro/dollar-crate-issue-57089.stdout | 80 |
3 files changed, 113 insertions, 0 deletions
diff --git a/src/test/ui/proc-macro/auxiliary/dollar-crate.rs b/src/test/ui/proc-macro/auxiliary/dollar-crate.rs index d0ea850d4e3..c5347d2e81a 100644 --- a/src/test/ui/proc-macro/auxiliary/dollar-crate.rs +++ b/src/test/ui/proc-macro/auxiliary/dollar-crate.rs @@ -7,6 +7,13 @@ extern crate proc_macro; use proc_macro::TokenStream; #[proc_macro] +pub fn m_empty(input: TokenStream) -> TokenStream { + println!("PROC MACRO INPUT (PRETTY-PRINTED): {}", input); + println!("PROC MACRO INPUT: {:#?}", input); + TokenStream::new() +} + +#[proc_macro] pub fn m(input: TokenStream) -> TokenStream { println!("PROC MACRO INPUT (PRETTY-PRINTED): {}", input); println!("PROC MACRO INPUT: {:#?}", input); diff --git a/src/test/ui/proc-macro/dollar-crate-issue-57089.rs b/src/test/ui/proc-macro/dollar-crate-issue-57089.rs new file mode 100644 index 00000000000..2d54c07ff95 --- /dev/null +++ b/src/test/ui/proc-macro/dollar-crate-issue-57089.rs @@ -0,0 +1,26 @@ +// compile-pass +// edition:2018 +// aux-build:dollar-crate.rs + +// Anonymize unstable non-dummy spans while still showing dummy spans `0..0`. +// normalize-stdout-test "bytes\([^0]\w*\.\.(\w+)\)" -> "bytes(LO..$1)" +// normalize-stdout-test "bytes\((\w+)\.\.[^0]\w*\)" -> "bytes($1..HI)" + +extern crate dollar_crate; + +type S = u8; + +macro_rules! m { + () => { + dollar_crate::m_empty! { + struct M($crate::S); + } + + #[dollar_crate::a] + struct A($crate::S); + }; +} + +m!(); + +fn main() {} diff --git a/src/test/ui/proc-macro/dollar-crate-issue-57089.stdout b/src/test/ui/proc-macro/dollar-crate-issue-57089.stdout new file mode 100644 index 00000000000..09340988c89 --- /dev/null +++ b/src/test/ui/proc-macro/dollar-crate-issue-57089.stdout @@ -0,0 +1,80 @@ +PROC MACRO INPUT (PRETTY-PRINTED): struct M ( $crate :: S ) ; +PROC MACRO INPUT: TokenStream [ + Ident { + ident: "struct", + span: #2 bytes(LO..HI) + }, + Ident { + ident: "M", + span: #2 bytes(LO..HI) + }, + Group { + delimiter: Parenthesis, + stream: TokenStream [ + Ident { + ident: "$crate", + span: #2 bytes(LO..HI) + }, + Punct { + ch: ':', + spacing: Joint, + span: #2 bytes(LO..HI) + }, + Punct { + ch: ':', + spacing: Alone, + span: #2 bytes(LO..HI) + }, + Ident { + ident: "S", + span: #2 bytes(LO..HI) + } + ], + span: #2 bytes(LO..HI) + }, + Punct { + ch: ';', + spacing: Alone, + span: #2 bytes(LO..HI) + } +] +ATTRIBUTE INPUT (PRETTY-PRINTED): struct A(crate::S); +ATTRIBUTE INPUT: TokenStream [ + Ident { + ident: "struct", + span: #2 bytes(LO..HI) + }, + Ident { + ident: "A", + span: #2 bytes(LO..HI) + }, + Group { + delimiter: Parenthesis, + stream: TokenStream [ + Ident { + ident: "$crate", + span: #2 bytes(LO..HI) + }, + Punct { + ch: ':', + spacing: Joint, + span: #2 bytes(LO..HI) + }, + Punct { + ch: ':', + spacing: Alone, + span: #2 bytes(LO..HI) + }, + Ident { + ident: "S", + span: #2 bytes(LO..HI) + } + ], + span: #2 bytes(LO..HI) + }, + Punct { + ch: ';', + spacing: Alone, + span: #2 bytes(LO..HI) + } +] |
