@@ -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 {
@@ -49,7 +49,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
49
49
}
50
50
_ => {
51
51
// Get the next normal token.
52
- let ( this_tok, this_spacing) = self . bump ( true ) ;
52
+ let ( this_tok, this_spacing) = self . bump ( ) ;
53
53
buf. push ( TokenTree :: Token ( this_tok, this_spacing) ) ;
54
54
}
55
55
}
@@ -138,7 +138,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
138
138
}
139
139
140
140
// Move past the closing delimiter.
141
- self . bump ( false ) . 1
141
+ self . bump_minimal ( )
142
142
}
143
143
// Incorrect delimiter.
144
144
token:: CloseDelim ( close_delim) => {
@@ -181,7 +181,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
181
181
// bar(baz(
182
182
// } // Incorrect delimiter but matches the earlier `{`
183
183
if !self . diag_info . open_braces . iter ( ) . any ( |& ( b, _) | b == close_delim) {
184
- self . bump ( false ) . 1
184
+ self . bump_minimal ( )
185
185
} else {
186
186
// The choice of value here doesn't matter.
187
187
Spacing :: Alone
@@ -203,14 +203,14 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
203
203
}
204
204
205
205
// Move on to the next token, returning the current token and its spacing.
206
- // Will glue adjacent single-char tokens together if `glue` is set .
207
- fn bump ( & mut self , glue : bool ) -> ( Token , Spacing ) {
206
+ // Will glue adjacent single-char tokens together.
207
+ fn bump ( & mut self ) -> ( Token , Spacing ) {
208
208
let ( this_spacing, next_tok) = loop {
209
209
let ( next_tok, is_next_tok_preceded_by_whitespace) = self . next_token_from_cursor ( ) ;
210
210
211
211
if is_next_tok_preceded_by_whitespace {
212
212
break ( Spacing :: Alone , next_tok) ;
213
- } else if glue && let Some ( glued) = self . token . glue ( & next_tok) {
213
+ } else if let Some ( glued) = self . token . glue ( & next_tok) {
214
214
self . token = glued;
215
215
} else {
216
216
let this_spacing = if next_tok. is_punct ( ) {
@@ -227,6 +227,26 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
227
227
( this_tok, this_spacing)
228
228
}
229
229
230
+ // Cut-down version of `bump` used when the token kind is known in advance.
231
+ fn bump_minimal ( & mut self ) -> Spacing {
232
+ let ( next_tok, is_next_tok_preceded_by_whitespace) = self . next_token_from_cursor ( ) ;
233
+
234
+ let this_spacing = if is_next_tok_preceded_by_whitespace {
235
+ Spacing :: Alone
236
+ } else {
237
+ if next_tok. is_punct ( ) {
238
+ Spacing :: Joint
239
+ } else if next_tok == token:: Eof {
240
+ Spacing :: Alone
241
+ } else {
242
+ Spacing :: JointHidden
243
+ }
244
+ } ;
245
+
246
+ self . token = next_tok;
247
+ this_spacing
248
+ }
249
+
230
250
fn unclosed_delim_err (
231
251
& mut self ,
232
252
tts : TokenStream ,
0 commit comments