Skip to content

Commit 77e677c

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

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

compiler/rustc_parse/src/lexer/tokentrees.rs

Lines changed: 13 additions & 19 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, false);
179173
break (this_spacing, next_tok);
180174
}
181175
};
@@ -186,21 +180,21 @@ 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();
183+
let this_spacing = self.calculate_spacing(&next_tok, is_next_tok_preceded_by_whitespace);
184+
self.token = next_tok;
185+
this_spacing
186+
}
189187

190-
let this_spacing = if is_next_tok_preceded_by_whitespace {
188+
fn calculate_spacing(&self, next_tok: &Token, is_preceded_by_whitespace: bool) -> Spacing {
189+
if is_preceded_by_whitespace {
190+
Spacing::Alone
191+
} else if next_tok.is_punct() {
192+
Spacing::Joint
193+
} else if *next_tok == token::Eof {
191194
Spacing::Alone
192195
} 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-
}
200-
};
201-
202-
self.token = next_tok;
203-
this_spacing
196+
Spacing::JointHidden
197+
}
204198
}
205199

206200
fn eof_err(&mut self) -> Diag<'psess> {

0 commit comments

Comments
 (0)