diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2022-09-26 12:57:37 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2022-09-26 13:35:43 +1000 |
| commit | 33ba2776c903dab45e4c9a8c9313ce5d59e69af1 (patch) | |
| tree | 925b9212f8aff119d58e99552f4592eae6462688 | |
| parent | 5b2075e03d90b53dddda4459ad299c1ffa9cf960 (diff) | |
| download | rust-33ba2776c903dab45e4c9a8c9313ce5d59e69af1.tar.gz rust-33ba2776c903dab45e4c9a8c9313ce5d59e69af1.zip | |
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.
| -rw-r--r-- | compiler/rustc_ast/src/token.rs | 7 | ||||
| -rw-r--r-- | compiler/rustc_parse/src/lexer/tokentrees.rs | 3 |
2 files changed, 2 insertions, 8 deletions
diff --git a/compiler/rustc_ast/src/token.rs b/compiler/rustc_ast/src/token.rs index 97dfb783767..fa6162c5184 100644 --- a/compiler/rustc_ast/src/token.rs +++ b/compiler/rustc_ast/src/token.rs @@ -13,7 +13,7 @@ use rustc_span::symbol::{kw, sym}; use rustc_span::symbol::{Ident, Symbol}; use rustc_span::{self, edition::Edition, Span, DUMMY_SP}; use std::borrow::Cow; -use std::{fmt, mem}; +use std::fmt; #[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)] pub enum CommentKind { @@ -335,11 +335,6 @@ impl Token { Token::new(Ident(ident.name, ident.is_raw_guess()), ident.span) } - /// Return this token by value and leave a dummy token in its place. - pub fn take(&mut self) -> Self { - mem::replace(self, Token::dummy()) - } - /// For interpolated tokens, returns a span of the fragment to which the interpolated /// token refers. For all other tokens this is just a regular span. /// It is particularly important to use this for identifiers and lifetimes diff --git a/compiler/rustc_parse/src/lexer/tokentrees.rs b/compiler/rustc_parse/src/lexer/tokentrees.rs index ae82d09ba41..c23090e7142 100644 --- a/compiler/rustc_parse/src/lexer/tokentrees.rs +++ b/compiler/rustc_parse/src/lexer/tokentrees.rs @@ -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) } } |
