@@ -16,7 +16,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
16
16
is_delimited : bool ,
17
17
) -> ( Spacing , TokenStream , Result < ( ) , Vec < PErr < ' psess > > > ) {
18
18
// Move past the opening delimiter.
19
- let open_spacing = self . bump ( false ) . 1 ;
19
+ let open_spacing = self . bump_minimal ( ) ;
20
20
21
21
let mut buf = Vec :: new ( ) ;
22
22
loop {
@@ -41,7 +41,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
41
41
}
42
42
_ => {
43
43
// Get the next normal token.
44
- let ( this_tok, this_spacing) = self . bump ( true ) ;
44
+ let ( this_tok, this_spacing) = self . bump ( ) ;
45
45
buf. push ( TokenTree :: Token ( this_tok, this_spacing) ) ;
46
46
}
47
47
}
@@ -130,7 +130,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
130
130
}
131
131
132
132
// Move past the closing delimiter.
133
- self . bump ( false ) . 1
133
+ self . bump_minimal ( )
134
134
}
135
135
// Incorrect delimiter.
136
136
token:: CloseDelim ( close_delim) => {
@@ -173,7 +173,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
173
173
// bar(baz(
174
174
// } // Incorrect delimiter but matches the earlier `{`
175
175
if !self . diag_info . open_braces . iter ( ) . any ( |& ( b, _) | b == close_delim) {
176
- self . bump ( false ) . 1
176
+ self . bump_minimal ( )
177
177
} else {
178
178
// The choice of value here doesn't matter.
179
179
Spacing :: Alone
@@ -195,14 +195,14 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
195
195
}
196
196
197
197
// Move on to the next token, returning the current token and its spacing.
198
- // Will glue adjacent single-char tokens together if `glue` is set .
199
- fn bump ( & mut self , glue : bool ) -> ( Token , Spacing ) {
198
+ // Will glue adjacent single-char tokens together.
199
+ fn bump ( & mut self ) -> ( Token , Spacing ) {
200
200
let ( this_spacing, next_tok) = loop {
201
201
let ( next_tok, is_next_tok_preceded_by_whitespace) = self . next_token_from_cursor ( ) ;
202
202
203
203
if is_next_tok_preceded_by_whitespace {
204
204
break ( Spacing :: Alone , next_tok) ;
205
- } else if glue && let Some ( glued) = self . token . glue ( & next_tok) {
205
+ } else if let Some ( glued) = self . token . glue ( & next_tok) {
206
206
self . token = glued;
207
207
} else {
208
208
let this_spacing = if next_tok. is_punct ( ) {
@@ -219,6 +219,26 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
219
219
( this_tok, this_spacing)
220
220
}
221
221
222
+ // Cut-down version of `bump` used when the token kind is known in advance.
223
+ fn bump_minimal ( & mut self ) -> Spacing {
224
+ let ( next_tok, is_next_tok_preceded_by_whitespace) = self . next_token_from_cursor ( ) ;
225
+
226
+ let this_spacing = if is_next_tok_preceded_by_whitespace {
227
+ Spacing :: Alone
228
+ } else {
229
+ if next_tok. is_punct ( ) {
230
+ Spacing :: Joint
231
+ } else if next_tok == token:: Eof {
232
+ Spacing :: Alone
233
+ } else {
234
+ Spacing :: JointHidden
235
+ }
236
+ } ;
237
+
238
+ self . token = next_tok;
239
+ this_spacing
240
+ }
241
+
222
242
fn unclosed_delim_err (
223
243
& mut self ,
224
244
tts : TokenStream ,
0 commit comments