Skip to content

Commit f9d4d12

Browse files
committed
Auto merge of rust-lang#95928 - nnethercote:rm-TokenTree-Clone, r=petrochenkov
Remove `<mbe::TokenTree as Clone>` `mbe::TokenTree` doesn't really need to implement `Clone`, and getting rid of that impl leads to some speed-ups. r? `@petrochenkov`
2 parents f387c93 + dd9028a commit f9d4d12

File tree

5 files changed

+164
-106
lines changed

5 files changed

+164
-106
lines changed

compiler/rustc_expand/src/mbe.rs

+5-18
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,19 @@ crate mod transcribe;
1313
use metavar_expr::MetaVarExpr;
1414
use rustc_ast::token::{self, NonterminalKind, Token, TokenKind};
1515
use rustc_ast::tokenstream::DelimSpan;
16-
use rustc_data_structures::sync::Lrc;
1716
use rustc_span::symbol::Ident;
1817
use rustc_span::Span;
1918

2019
/// Contains the sub-token-trees of a "delimited" token tree such as `(a b c)`. The delimiters
2120
/// might be `NoDelim`, but they are not represented explicitly.
22-
#[derive(Clone, PartialEq, Encodable, Decodable, Debug)]
21+
#[derive(PartialEq, Encodable, Decodable, Debug)]
2322
struct Delimited {
2423
delim: token::DelimToken,
2524
/// FIXME: #67062 has details about why this is sub-optimal.
2625
tts: Vec<TokenTree>,
2726
}
2827

29-
impl Delimited {
30-
/// Returns a `self::TokenTree` with a `Span` corresponding to the opening delimiter.
31-
fn open_tt(&self, span: DelimSpan) -> TokenTree {
32-
TokenTree::token(token::OpenDelim(self.delim), span.open)
33-
}
34-
35-
/// Returns a `self::TokenTree` with a `Span` corresponding to the closing delimiter.
36-
fn close_tt(&self, span: DelimSpan) -> TokenTree {
37-
TokenTree::token(token::CloseDelim(self.delim), span.close)
38-
}
39-
}
40-
41-
#[derive(Clone, PartialEq, Encodable, Decodable, Debug)]
28+
#[derive(PartialEq, Encodable, Decodable, Debug)]
4229
struct SequenceRepetition {
4330
/// The sequence of token trees
4431
tts: Vec<TokenTree>,
@@ -76,13 +63,13 @@ enum KleeneOp {
7663

7764
/// Similar to `tokenstream::TokenTree`, except that `Sequence`, `MetaVar`, `MetaVarDecl`, and
7865
/// `MetaVarExpr` are "first-class" token trees. Useful for parsing macros.
79-
#[derive(Debug, Clone, PartialEq, Encodable, Decodable)]
66+
#[derive(Debug, PartialEq, Encodable, Decodable)]
8067
enum TokenTree {
8168
Token(Token),
8269
/// A delimited sequence, e.g. `($e:expr)` (RHS) or `{ $e }` (LHS).
83-
Delimited(DelimSpan, Lrc<Delimited>),
70+
Delimited(DelimSpan, Delimited),
8471
/// A kleene-style repetition sequence, e.g. `$($e:expr)*` (RHS) or `$($e),*` (LHS).
85-
Sequence(DelimSpan, Lrc<SequenceRepetition>),
72+
Sequence(DelimSpan, SequenceRepetition),
8673
/// e.g., `$var`.
8774
MetaVar(Span, Ident),
8875
/// e.g., `$var:expr`. Only appears on the LHS.

compiler/rustc_expand/src/mbe/macro_parser.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,13 @@ pub(super) fn compute_locs(sess: &ParseSess, matcher: &[TokenTree]) -> Vec<Match
142142
locs.push(MatcherLoc::Token { token: token.clone() });
143143
}
144144
TokenTree::Delimited(span, delimited) => {
145+
let open_token = Token::new(token::OpenDelim(delimited.delim), span.open);
146+
let close_token = Token::new(token::CloseDelim(delimited.delim), span.close);
147+
145148
locs.push(MatcherLoc::Delimited);
146-
inner(sess, &[delimited.open_tt(*span)], locs, next_metavar, seq_depth);
149+
locs.push(MatcherLoc::Token { token: open_token });
147150
inner(sess, &delimited.tts, locs, next_metavar, seq_depth);
148-
inner(sess, &[delimited.close_tt(*span)], locs, next_metavar, seq_depth);
151+
locs.push(MatcherLoc::Token { token: close_token });
149152
}
150153
TokenTree::Sequence(_, seq) => {
151154
// We can't determine `idx_first_after` and construct the final

0 commit comments

Comments
 (0)