File tree Expand file tree Collapse file tree 4 files changed +128
-0
lines changed Expand file tree Collapse file tree 4 files changed +128
-0
lines changed Original file line number Diff line number Diff line change 66extern crate proc_macro;
77use proc_macro:: TokenStream ;
88
9+ #[ proc_macro]
10+ pub fn m_empty ( input : TokenStream ) -> TokenStream {
11+ println ! ( "PROC MACRO INPUT (PRETTY-PRINTED): {}" , input) ;
12+ println ! ( "PROC MACRO INPUT: {:#?}" , input) ;
13+ TokenStream :: new ( )
14+ }
15+
916#[ proc_macro]
1017pub fn m ( input : TokenStream ) -> TokenStream {
1118 println ! ( "PROC MACRO INPUT (PRETTY-PRINTED): {}" , input) ;
Original file line number Diff line number Diff line change 1+ // edition:2018
2+ // aux-build:dollar-crate.rs
3+
4+ // Anonymize unstable non-dummy spans while still showing dummy spans `0..0`.
5+ // normalize-stdout-test "bytes\([^0]\w*\.\.(\w+)\)" -> "bytes(LO..$1)"
6+ // normalize-stdout-test "bytes\((\w+)\.\.[^0]\w*\)" -> "bytes($1..HI)"
7+
8+ extern crate dollar_crate;
9+
10+ type S = u8 ;
11+
12+ macro_rules! m {
13+ ( ) => {
14+ dollar_crate:: m_empty! {
15+ struct M ( $crate:: S ) ;
16+ }
17+
18+ #[ dollar_crate:: a] //~ ERROR expected type, found `$`
19+ struct A ( $crate:: S ) ;
20+ } ;
21+ }
22+
23+ m ! ( ) ;
24+
25+ fn main ( ) { }
Original file line number Diff line number Diff line change 1+ error: expected type, found `$`
2+ --> $DIR/dollar-crate-in-tokens.rs:18:9
3+ |
4+ LL | #[dollar_crate::a] //~ ERROR expected type, found `$`
5+ | ^^^^^^^^^^^^^^^^^^
6+ ...
7+ LL | m!();
8+ | ----- in this macro invocation
9+
10+ error: aborting due to previous error
11+
Original file line number Diff line number Diff line change 1+ PROC MACRO INPUT (PRETTY-PRINTED): struct M ( $crate :: S ) ;
2+ PROC MACRO INPUT: TokenStream [
3+ Ident {
4+ ident: "struct",
5+ span: #2 bytes(LO..HI)
6+ },
7+ Ident {
8+ ident: "M",
9+ span: #2 bytes(LO..HI)
10+ },
11+ Group {
12+ delimiter: Parenthesis,
13+ stream: TokenStream [
14+ Ident {
15+ ident: "$crate",
16+ span: #2 bytes(LO..HI)
17+ },
18+ Punct {
19+ ch: ':',
20+ spacing: Joint,
21+ span: #2 bytes(LO..HI)
22+ },
23+ Punct {
24+ ch: ':',
25+ spacing: Alone,
26+ span: #2 bytes(LO..HI)
27+ },
28+ Ident {
29+ ident: "S",
30+ span: #2 bytes(LO..HI)
31+ }
32+ ],
33+ span: #2 bytes(LO..HI)
34+ },
35+ Punct {
36+ ch: ';',
37+ spacing: Alone,
38+ span: #2 bytes(LO..HI)
39+ }
40+ ]
41+ ATTRIBUTE INPUT (PRETTY-PRINTED): struct A($crate::S);
42+ ATTRIBUTE INPUT: TokenStream [
43+ Ident {
44+ ident: "struct",
45+ span: #0 bytes(0..0)
46+ },
47+ Ident {
48+ ident: "A",
49+ span: #0 bytes(0..0)
50+ },
51+ Group {
52+ delimiter: Parenthesis,
53+ stream: TokenStream [
54+ Punct {
55+ ch: '$',
56+ spacing: Alone,
57+ span: #0 bytes(0..0)
58+ },
59+ Ident {
60+ ident: "crate",
61+ span: #0 bytes(0..0)
62+ },
63+ Punct {
64+ ch: ':',
65+ spacing: Joint,
66+ span: #0 bytes(0..0)
67+ },
68+ Punct {
69+ ch: ':',
70+ spacing: Alone,
71+ span: #0 bytes(0..0)
72+ },
73+ Ident {
74+ ident: "S",
75+ span: #0 bytes(0..0)
76+ }
77+ ],
78+ span: #0 bytes(0..0)
79+ },
80+ Punct {
81+ ch: ';',
82+ spacing: Alone,
83+ span: #0 bytes(0..0)
84+ }
85+ ]
You can’t perform that action at this time.
0 commit comments