1
Fork 0

Remove ast::Token::take.

Instead of replacing `TokenTreesReader::token` in two steps, we can just
do it in one, which is both simpler and faster.
This commit is contained in:
Nicholas Nethercote 2022-09-26 12:57:37 +10:00
parent 5b2075e03d
commit 33ba2776c9
2 changed files with 2 additions and 8 deletions

View file

@ -247,14 +247,13 @@ impl<'a> TokenTreesReader<'a> {
fn parse_token_tree_other(&mut self) -> TokenTree {
// `spacing` for the returned token is determined by the next token:
// its kind and its `preceded_by_whitespace` status.
let this_tok = self.token.take();
let (next_tok, is_next_tok_preceded_by_whitespace) = self.string_reader.next_token();
let this_spacing = if is_next_tok_preceded_by_whitespace || !next_tok.is_op() {
Spacing::Alone
} else {
Spacing::Joint
};
self.token = next_tok;
let this_tok = std::mem::replace(&mut self.token, next_tok);
TokenTree::Token(this_tok, this_spacing)
}
}