Add test demonstrating disintegration of $crate
into $
and crate
This commit is contained in:
parent
bc09637e21
commit
24af9f88a5
4 changed files with 128 additions and 0 deletions
|
@ -6,6 +6,13 @@
|
||||||
extern crate proc_macro;
|
extern crate proc_macro;
|
||||||
use proc_macro::TokenStream;
|
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]
|
#[proc_macro]
|
||||||
pub fn m(input: TokenStream) -> TokenStream {
|
pub fn m(input: TokenStream) -> TokenStream {
|
||||||
println!("PROC MACRO INPUT (PRETTY-PRINTED): {}", input);
|
println!("PROC MACRO INPUT (PRETTY-PRINTED): {}", input);
|
||||||
|
|
25
src/test/ui/proc-macro/dollar-crate-issue-57089.rs
Normal file
25
src/test/ui/proc-macro/dollar-crate-issue-57089.rs
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
// 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] //~ ERROR expected type, found `$`
|
||||||
|
struct A($crate::S);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
m!();
|
||||||
|
|
||||||
|
fn main() {}
|
11
src/test/ui/proc-macro/dollar-crate-issue-57089.stderr
Normal file
11
src/test/ui/proc-macro/dollar-crate-issue-57089.stderr
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
error: expected type, found `$`
|
||||||
|
--> $DIR/dollar-crate-in-tokens.rs:18:9
|
||||||
|
|
|
||||||
|
LL | #[dollar_crate::a] //~ ERROR expected type, found `$`
|
||||||
|
| ^^^^^^^^^^^^^^^^^^
|
||||||
|
...
|
||||||
|
LL | m!();
|
||||||
|
| ----- in this macro invocation
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
85
src/test/ui/proc-macro/dollar-crate-issue-57089.stdout
Normal file
85
src/test/ui/proc-macro/dollar-crate-issue-57089.stdout
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
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: #0 bytes(0..0)
|
||||||
|
},
|
||||||
|
Ident {
|
||||||
|
ident: "A",
|
||||||
|
span: #0 bytes(0..0)
|
||||||
|
},
|
||||||
|
Group {
|
||||||
|
delimiter: Parenthesis,
|
||||||
|
stream: TokenStream [
|
||||||
|
Punct {
|
||||||
|
ch: '$',
|
||||||
|
spacing: Alone,
|
||||||
|
span: #0 bytes(0..0)
|
||||||
|
},
|
||||||
|
Ident {
|
||||||
|
ident: "crate",
|
||||||
|
span: #0 bytes(0..0)
|
||||||
|
},
|
||||||
|
Punct {
|
||||||
|
ch: ':',
|
||||||
|
spacing: Joint,
|
||||||
|
span: #0 bytes(0..0)
|
||||||
|
},
|
||||||
|
Punct {
|
||||||
|
ch: ':',
|
||||||
|
spacing: Alone,
|
||||||
|
span: #0 bytes(0..0)
|
||||||
|
},
|
||||||
|
Ident {
|
||||||
|
ident: "S",
|
||||||
|
span: #0 bytes(0..0)
|
||||||
|
}
|
||||||
|
],
|
||||||
|
span: #0 bytes(0..0)
|
||||||
|
},
|
||||||
|
Punct {
|
||||||
|
ch: ';',
|
||||||
|
spacing: Alone,
|
||||||
|
span: #0 bytes(0..0)
|
||||||
|
}
|
||||||
|
]
|
Loading…
Add table
Add a link
Reference in a new issue