Skip to content

Commit 33ba277

Browse files
committed
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.
1 parent 5b2075e commit 33ba277

File tree

2 files changed

+2
-8
lines changed

2 files changed

+2
-8
lines changed

compiler/rustc_ast/src/token.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_span::symbol::{kw, sym};
1313
use rustc_span::symbol::{Ident, Symbol};
1414
use rustc_span::{self, edition::Edition, Span, DUMMY_SP};
1515
use std::borrow::Cow;
16-
use std::{fmt, mem};
16+
use std::fmt;
1717

1818
#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
1919
pub enum CommentKind {
@@ -335,11 +335,6 @@ impl Token {
335335
Token::new(Ident(ident.name, ident.is_raw_guess()), ident.span)
336336
}
337337

338-
/// Return this token by value and leave a dummy token in its place.
339-
pub fn take(&mut self) -> Self {
340-
mem::replace(self, Token::dummy())
341-
}
342-
343338
/// For interpolated tokens, returns a span of the fragment to which the interpolated
344339
/// token refers. For all other tokens this is just a regular span.
345340
/// It is particularly important to use this for identifiers and lifetimes

compiler/rustc_parse/src/lexer/tokentrees.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,13 @@ impl<'a> TokenTreesReader<'a> {
247247
fn parse_token_tree_other(&mut self) -> TokenTree {
248248
// `spacing` for the returned token is determined by the next token:
249249
// its kind and its `preceded_by_whitespace` status.
250-
let this_tok = self.token.take();
251250
let (next_tok, is_next_tok_preceded_by_whitespace) = self.string_reader.next_token();
252251
let this_spacing = if is_next_tok_preceded_by_whitespace || !next_tok.is_op() {
253252
Spacing::Alone
254253
} else {
255254
Spacing::Joint
256255
};
257-
self.token = next_tok;
256+
let this_tok = std::mem::replace(&mut self.token, next_tok);
258257
TokenTree::Token(this_tok, this_spacing)
259258
}
260259
}

0 commit comments

Comments
 (0)