@@ -16,7 +16,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
1616 is_delimited : bool ,
1717 ) -> ( Spacing , TokenStream , Result < ( ) , Vec < PErr < ' psess > > > ) {
1818 // Move past the opening delimiter.
19- let open_spacing = self . bump ( false ) . 1 ;
19+ let open_spacing = self . bump_minimal ( ) ;
2020
2121 let mut buf = Vec :: new ( ) ;
2222 loop {
@@ -49,7 +49,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
4949 }
5050 _ => {
5151 // Get the next normal token.
52- let ( this_tok, this_spacing) = self . bump ( true ) ;
52+ let ( this_tok, this_spacing) = self . bump ( ) ;
5353 buf. push ( TokenTree :: Token ( this_tok, this_spacing) ) ;
5454 }
5555 }
@@ -138,7 +138,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
138138 }
139139
140140 // Move past the closing delimiter.
141- self . bump ( false ) . 1
141+ self . bump_minimal ( )
142142 }
143143 // Incorrect delimiter.
144144 token:: CloseDelim ( close_delim) => {
@@ -181,7 +181,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
181181 // bar(baz(
182182 // } // Incorrect delimiter but matches the earlier `{`
183183 if !self . diag_info . open_braces . iter ( ) . any ( |& ( b, _) | b == close_delim) {
184- self . bump ( false ) . 1
184+ self . bump_minimal ( )
185185 } else {
186186 // The choice of value here doesn't matter.
187187 Spacing :: Alone
@@ -203,14 +203,14 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
203203 }
204204
205205 // 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 ) {
208208 let ( this_spacing, next_tok) = loop {
209209 let ( next_tok, is_next_tok_preceded_by_whitespace) = self . next_token_from_cursor ( ) ;
210210
211211 if is_next_tok_preceded_by_whitespace {
212212 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) {
214214 self . token = glued;
215215 } else {
216216 let this_spacing = if next_tok. is_punct ( ) {
@@ -227,6 +227,26 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
227227 ( this_tok, this_spacing)
228228 }
229229
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+
230250 fn unclosed_delim_err (
231251 & mut self ,
232252 tts : TokenStream ,
0 commit comments