Skip to content

Commit 896d8f5

Browse files
committed
Remove the lifetime from TtParser and MatcherLoc.
It's a slight performance loss for now, but that will be recouped by the next commit.
1 parent 6a9080b commit 896d8f5

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

compiler/rustc_expand/src/mbe/macro_parser.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ rustc_data_structures::static_assert_size!(NamedMatchVec, 48);
106106
///
107107
/// This means a matcher can be represented by `&[MatcherLoc]`, and traversal mostly involves
108108
/// simply incrementing the current matcher position index by one.
109-
enum MatcherLoc<'tt> {
109+
enum MatcherLoc {
110110
Token {
111-
token: &'tt Token,
111+
token: Token,
112112
},
113113
Delimited,
114114
Sequence {
@@ -123,7 +123,7 @@ enum MatcherLoc<'tt> {
123123
idx_first: usize,
124124
},
125125
SequenceSep {
126-
separator: &'tt Token,
126+
separator: Token,
127127
},
128128
SequenceKleeneOpAfterSep {
129129
idx_first: usize,
@@ -298,11 +298,11 @@ fn token_name_eq(t1: &Token, t2: &Token) -> bool {
298298

299299
// Note: the vectors could be created and dropped within `parse_tt`, but to avoid excess
300300
// allocations we have a single vector fo each kind that is cleared and reused repeatedly.
301-
pub struct TtParser<'tt> {
301+
pub struct TtParser {
302302
macro_name: Ident,
303303

304304
/// The matcher of the current rule.
305-
locs: Vec<MatcherLoc<'tt>>,
305+
locs: Vec<MatcherLoc>,
306306

307307
/// The set of current mps to be processed. This should be empty by the end of a successful
308308
/// execution of `parse_tt_inner`.
@@ -320,8 +320,8 @@ pub struct TtParser<'tt> {
320320
empty_matches: Lrc<NamedMatchVec>,
321321
}
322322

323-
impl<'tt> TtParser<'tt> {
324-
pub(super) fn new(macro_name: Ident) -> TtParser<'tt> {
323+
impl TtParser {
324+
pub(super) fn new(macro_name: Ident) -> TtParser {
325325
TtParser {
326326
macro_name,
327327
locs: vec![],
@@ -340,19 +340,19 @@ impl<'tt> TtParser<'tt> {
340340
fn compute_locs(
341341
&mut self,
342342
sess: &ParseSess,
343-
matcher: &'tt [TokenTree],
343+
matcher: &[TokenTree],
344344
) -> Result<usize, (Span, String)> {
345-
fn inner<'tt>(
345+
fn inner(
346346
sess: &ParseSess,
347-
tts: &'tt [TokenTree],
348-
locs: &mut Vec<MatcherLoc<'tt>>,
347+
tts: &[TokenTree],
348+
locs: &mut Vec<MatcherLoc>,
349349
next_metavar: &mut usize,
350350
seq_depth: usize,
351351
) -> Result<(), (Span, String)> {
352352
for tt in tts {
353353
match tt {
354354
TokenTree::Token(token) => {
355-
locs.push(MatcherLoc::Token { token });
355+
locs.push(MatcherLoc::Token { token: token.clone() });
356356
}
357357
TokenTree::Delimited(_, delimited) => {
358358
locs.push(MatcherLoc::Delimited);
@@ -373,7 +373,7 @@ impl<'tt> TtParser<'tt> {
373373
inner(sess, &seq.tts, locs, next_metavar, seq_depth + 1)?;
374374

375375
if let Some(separator) = &seq.separator {
376-
locs.push(MatcherLoc::SequenceSep { separator });
376+
locs.push(MatcherLoc::SequenceSep { separator: separator.clone() });
377377
locs.push(MatcherLoc::SequenceKleeneOpAfterSep { idx_first });
378378
} else {
379379
locs.push(MatcherLoc::SequenceKleeneOpNoSep { op, idx_first });
@@ -586,7 +586,7 @@ impl<'tt> TtParser<'tt> {
586586
pub(super) fn parse_tt(
587587
&mut self,
588588
parser: &mut Cow<'_, Parser<'_>>,
589-
matcher: &'tt [TokenTree],
589+
matcher: &[TokenTree],
590590
) -> NamedParseResult {
591591
let num_metavar_decls = match self.compute_locs(parser.sess, matcher) {
592592
Ok(num_metavar_decls) => num_metavar_decls,

0 commit comments

Comments
 (0)