Skip to content

Commit 1a0850c

Browse files
committed
Split Lexer::bump.
It has two different ways of being called.
1 parent 68a5043 commit 1a0850c

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

compiler/rustc_parse/src/lexer/tokentrees.rs

+27-7
Original file line numberDiff line numberDiff line change
@@ -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 {
@@ -41,7 +41,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
4141
}
4242
_ => {
4343
// Get the next normal token.
44-
let (this_tok, this_spacing) = self.bump(true);
44+
let (this_tok, this_spacing) = self.bump();
4545
buf.push(TokenTree::Token(this_tok, this_spacing));
4646
}
4747
}
@@ -130,7 +130,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
130130
}
131131

132132
// Move past the closing delimiter.
133-
self.bump(false).1
133+
self.bump_minimal()
134134
}
135135
// Incorrect delimiter.
136136
token::CloseDelim(close_delim) => {
@@ -173,7 +173,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
173173
// bar(baz(
174174
// } // Incorrect delimiter but matches the earlier `{`
175175
if !self.diag_info.open_braces.iter().any(|&(b, _)| b == close_delim) {
176-
self.bump(false).1
176+
self.bump_minimal()
177177
} else {
178178
// The choice of value here doesn't matter.
179179
Spacing::Alone
@@ -195,14 +195,14 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
195195
}
196196

197197
// 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) {
200200
let (this_spacing, next_tok) = loop {
201201
let (next_tok, is_next_tok_preceded_by_whitespace) = self.next_token_from_cursor();
202202

203203
if is_next_tok_preceded_by_whitespace {
204204
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) {
206206
self.token = glued;
207207
} else {
208208
let this_spacing = if next_tok.is_punct() {
@@ -219,6 +219,26 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
219219
(this_tok, this_spacing)
220220
}
221221

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+
222242
fn unclosed_delim_err(
223243
&mut self,
224244
tts: TokenStream,

0 commit comments

Comments
 (0)