Skip to content

Commit f756257

Browse files
committed
Do not interpret mismatches from pretty-printed $crate as token stream invalidation
1 parent 69c6628 commit f756257

File tree

4 files changed

+50
-60
lines changed

4 files changed

+50
-60
lines changed

src/libsyntax/parse/token.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,9 @@ impl Token {
633633
(&Shebang(a), &Shebang(b)) => a == b,
634634

635635
(&Lifetime(a), &Lifetime(b)) => a.name == b.name,
636-
(&Ident(a, b), &Ident(c, d)) => a.name == c.name && b == d,
636+
(&Ident(a, b), &Ident(c, d)) => b == d && (a.name == c.name ||
637+
a.name == keywords::DollarCrate.name() ||
638+
c.name == keywords::DollarCrate.name()),
637639

638640
(&Literal(ref a, b), &Literal(ref c, d)) => {
639641
b == d && a.probably_equal_for_proc_macro(c)

src/libsyntax/tokenstream.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,9 @@ impl TokenStream {
348348
| TokenTree::Token(_, Token::Semi)
349349
// The pretty printer collapses whitespace arbitrarily and can
350350
// introduce whitespace from `NoDelim`.
351-
| TokenTree::Token(_, Token::Whitespace) => false,
351+
| TokenTree::Token(_, Token::Whitespace)
352+
// The pretty printer can turn `$crate` into `::crate_name`
353+
| TokenTree::Token(_, Token::ModSep) => false,
352354
_ => true
353355
}
354356
}

src/test/ui/proc-macro/dollar-crate.stderr

+8-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ error[E0428]: the name `D` is defined multiple times
22
--> $DIR/dollar-crate.rs:23:13
33
|
44
LL | struct D($crate::S); //~ ERROR the name `D` is defined multiple times
5-
| ^^^^^^^^^^^^^^^^^^^^ `D` redefined here
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
| |
7+
| `D` redefined here
8+
| previous definition of the type `D` here
69
...
710
LL | local!();
811
| --------- in this macro invocation
@@ -13,7 +16,10 @@ error[E0428]: the name `D` is defined multiple times
1316
--> $DIR/dollar-crate.rs:31:5
1417
|
1518
LL | dollar_crate_external::external!(); //~ ERROR the name `D` is defined multiple times
16-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `D` redefined here
19+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20+
| |
21+
| `D` redefined here
22+
| previous definition of the type `D` here
1723
|
1824
= note: `D` must be defined only once in the type namespace of this module
1925
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

src/test/ui/proc-macro/dollar-crate.stdout

+36-56
Original file line numberDiff line numberDiff line change
@@ -42,80 +42,80 @@ ATTRIBUTE INPUT (PRETTY-PRINTED): struct A(crate::S);
4242
ATTRIBUTE INPUT: TokenStream [
4343
Ident {
4444
ident: "struct",
45-
span: #0 bytes(0..0)
45+
span: #2 bytes(LO..HI)
4646
},
4747
Ident {
4848
ident: "A",
49-
span: #0 bytes(0..0)
49+
span: #2 bytes(LO..HI)
5050
},
5151
Group {
5252
delimiter: Parenthesis,
5353
stream: TokenStream [
5454
Ident {
55-
ident: "crate",
56-
span: #0 bytes(0..0)
55+
ident: "$crate",
56+
span: #2 bytes(LO..HI)
5757
},
5858
Punct {
5959
ch: ':',
6060
spacing: Joint,
61-
span: #0 bytes(0..0)
61+
span: #2 bytes(LO..HI)
6262
},
6363
Punct {
6464
ch: ':',
6565
spacing: Alone,
66-
span: #0 bytes(0..0)
66+
span: #2 bytes(LO..HI)
6767
},
6868
Ident {
6969
ident: "S",
70-
span: #0 bytes(0..0)
70+
span: #2 bytes(LO..HI)
7171
}
7272
],
73-
span: #0 bytes(0..0)
73+
span: #2 bytes(LO..HI)
7474
},
7575
Punct {
7676
ch: ';',
7777
spacing: Alone,
78-
span: #0 bytes(0..0)
78+
span: #2 bytes(LO..HI)
7979
}
8080
]
8181
DERIVE INPUT (PRETTY-PRINTED): struct D(crate::S);
8282
DERIVE INPUT: TokenStream [
8383
Ident {
8484
ident: "struct",
85-
span: #0 bytes(0..0)
85+
span: #2 bytes(LO..HI)
8686
},
8787
Ident {
8888
ident: "D",
89-
span: #0 bytes(0..0)
89+
span: #2 bytes(LO..HI)
9090
},
9191
Group {
9292
delimiter: Parenthesis,
9393
stream: TokenStream [
9494
Ident {
95-
ident: "crate",
96-
span: #0 bytes(0..0)
95+
ident: "$crate",
96+
span: #2 bytes(LO..HI)
9797
},
9898
Punct {
9999
ch: ':',
100100
spacing: Joint,
101-
span: #0 bytes(0..0)
101+
span: #2 bytes(LO..HI)
102102
},
103103
Punct {
104104
ch: ':',
105105
spacing: Alone,
106-
span: #0 bytes(0..0)
106+
span: #2 bytes(LO..HI)
107107
},
108108
Ident {
109109
ident: "S",
110-
span: #0 bytes(0..0)
110+
span: #2 bytes(LO..HI)
111111
}
112112
],
113-
span: #0 bytes(0..0)
113+
span: #2 bytes(LO..HI)
114114
},
115115
Punct {
116116
ch: ';',
117117
spacing: Alone,
118-
span: #0 bytes(0..0)
118+
span: #2 bytes(LO..HI)
119119
}
120120
]
121121
PROC MACRO INPUT (PRETTY-PRINTED): struct M ( $crate :: S ) ;
@@ -162,99 +162,79 @@ ATTRIBUTE INPUT (PRETTY-PRINTED): struct A(::dollar_crate_external::S);
162162
ATTRIBUTE INPUT: TokenStream [
163163
Ident {
164164
ident: "struct",
165-
span: #0 bytes(0..0)
165+
span: #10 bytes(LO..HI)
166166
},
167167
Ident {
168168
ident: "A",
169-
span: #0 bytes(0..0)
169+
span: #10 bytes(LO..HI)
170170
},
171171
Group {
172172
delimiter: Parenthesis,
173173
stream: TokenStream [
174-
Punct {
175-
ch: ':',
176-
spacing: Joint,
177-
span: #0 bytes(0..0)
178-
},
179-
Punct {
180-
ch: ':',
181-
spacing: Alone,
182-
span: #0 bytes(0..0)
183-
},
184174
Ident {
185-
ident: "dollar_crate_external",
186-
span: #0 bytes(0..0)
175+
ident: "$crate",
176+
span: #10 bytes(LO..HI)
187177
},
188178
Punct {
189179
ch: ':',
190180
spacing: Joint,
191-
span: #0 bytes(0..0)
181+
span: #10 bytes(LO..HI)
192182
},
193183
Punct {
194184
ch: ':',
195185
spacing: Alone,
196-
span: #0 bytes(0..0)
186+
span: #10 bytes(LO..HI)
197187
},
198188
Ident {
199189
ident: "S",
200-
span: #0 bytes(0..0)
190+
span: #10 bytes(LO..HI)
201191
}
202192
],
203-
span: #0 bytes(0..0)
193+
span: #10 bytes(LO..HI)
204194
},
205195
Punct {
206196
ch: ';',
207197
spacing: Alone,
208-
span: #0 bytes(0..0)
198+
span: #10 bytes(LO..HI)
209199
}
210200
]
211201
DERIVE INPUT (PRETTY-PRINTED): struct D(::dollar_crate_external::S);
212202
DERIVE INPUT: TokenStream [
213203
Ident {
214204
ident: "struct",
215-
span: #0 bytes(0..0)
205+
span: #10 bytes(LO..HI)
216206
},
217207
Ident {
218208
ident: "D",
219-
span: #0 bytes(0..0)
209+
span: #10 bytes(LO..HI)
220210
},
221211
Group {
222212
delimiter: Parenthesis,
223213
stream: TokenStream [
224-
Punct {
225-
ch: ':',
226-
spacing: Joint,
227-
span: #0 bytes(0..0)
228-
},
229-
Punct {
230-
ch: ':',
231-
spacing: Alone,
232-
span: #0 bytes(0..0)
233-
},
234214
Ident {
235-
ident: "dollar_crate_external",
236-
span: #0 bytes(0..0)
215+
ident: "$crate",
216+
span: #10 bytes(LO..HI)
237217
},
238218
Punct {
239219
ch: ':',
240220
spacing: Joint,
241-
span: #0 bytes(0..0)
221+
span: #10 bytes(LO..HI)
242222
},
243223
Punct {
244224
ch: ':',
245225
spacing: Alone,
246-
span: #0 bytes(0..0)
226+
span: #10 bytes(LO..HI)
247227
},
248228
Ident {
249229
ident: "S",
250-
span: #0 bytes(0..0)
230+
span: #10 bytes(LO..HI)
251231
}
252232
],
253-
span: #0 bytes(0..0)
233+
span: #10 bytes(LO..HI)
254234
},
255235
Punct {
256236
ch: ';',
257237
spacing: Alone,
258-
span: #0 bytes(0..0)
238+
span: #10 bytes(LO..HI)
259239
}
260240
]

0 commit comments

Comments
 (0)