Skip to content

Commit fc236ea

Browse files
committed
Add calculate_spacing for bump and bump_minimal
Signed-off-by: xizheyin <[email protected]>
1 parent 3c88694 commit fc236ea

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

compiler/rustc_parse/src/lexer/tokentrees.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
169169
} else if let Some(glued) = self.token.glue(&next_tok) {
170170
self.token = glued;
171171
} else {
172-
let this_spacing = if next_tok.is_punct() {
173-
Spacing::Joint
174-
} else if next_tok == token::Eof {
175-
Spacing::Alone
176-
} else {
177-
Spacing::JointHidden
178-
};
172+
let this_spacing = self.calculate_spacing(&next_tok);
179173
break (this_spacing, next_tok);
180174
}
181175
};
@@ -186,23 +180,25 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
186180
// Cut-down version of `bump` used when the token kind is known in advance.
187181
fn bump_minimal(&mut self) -> Spacing {
188182
let (next_tok, is_next_tok_preceded_by_whitespace) = self.next_token_from_cursor();
189-
190183
let this_spacing = if is_next_tok_preceded_by_whitespace {
191184
Spacing::Alone
192185
} else {
193-
if next_tok.is_punct() {
194-
Spacing::Joint
195-
} else if next_tok == token::Eof {
196-
Spacing::Alone
197-
} else {
198-
Spacing::JointHidden
199-
}
186+
self.calculate_spacing(&next_tok)
200187
};
201-
202188
self.token = next_tok;
203189
this_spacing
204190
}
205191

192+
fn calculate_spacing(&self, next_tok: &Token) -> Spacing {
193+
if next_tok.is_punct() {
194+
Spacing::Joint
195+
} else if *next_tok == token::Eof {
196+
Spacing::Alone
197+
} else {
198+
Spacing::JointHidden
199+
}
200+
}
201+
206202
fn eof_err(&mut self) -> Diag<'psess> {
207203
let msg = "this file contains an unclosed delimiter";
208204
let mut err = self.dcx().struct_span_err(self.token.span, msg);

0 commit comments

Comments
 (0)