Skip to content

Commit dbd8220

Browse files
committed
Avoid base_parser, it's not needed.
1 parent d538b80 commit dbd8220

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

src/librustc_expand/mbe/macro_rules.rs

+11-14
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,9 @@ fn generic_extension<'cx>(
191191
let mut best_failure: Option<(Token, &str)> = None;
192192

193193
// We create a base parser that can be used for the "black box" parts.
194-
// Every iteration needs a fresh copy of that base parser. However, the
195-
// parser is not mutated on many of the iterations, particularly when
196-
// dealing with macros like this:
194+
// Every iteration needs a fresh copy of that parser. However, the parser
195+
// is not mutated on many of the iterations, particularly when dealing with
196+
// macros like this:
197197
//
198198
// macro_rules! foo {
199199
// ("a") => (A);
@@ -209,11 +209,9 @@ fn generic_extension<'cx>(
209209
// hacky, but speeds up the `html5ever` benchmark significantly. (Issue
210210
// 68836 suggests a more comprehensive but more complex change to deal with
211211
// this situation.)
212-
let base_parser = base_parser_from_cx(&cx.current_expansion, &cx.parse_sess, arg.clone());
212+
let parser = parser_from_cx(&cx.current_expansion, &cx.parse_sess, arg.clone());
213213

214214
for (i, lhs) in lhses.iter().enumerate() {
215-
let mut parser = Cow::Borrowed(&base_parser);
216-
217215
// try each arm's matchers
218216
let lhs_tt = match *lhs {
219217
mbe::TokenTree::Delimited(_, ref delim) => &delim.tts[..],
@@ -226,7 +224,7 @@ fn generic_extension<'cx>(
226224
// are not recorded. On the first `Success(..)`ful matcher, the spans are merged.
227225
let mut gated_spans_snaphot = mem::take(&mut *cx.parse_sess.gated_spans.spans.borrow_mut());
228226

229-
match parse_tt(&mut parser, lhs_tt) {
227+
match parse_tt(&mut Cow::Borrowed(&parser), lhs_tt) {
230228
Success(named_matches) => {
231229
// The matcher was `Success(..)`ful.
232230
// Merge the gated spans from parsing the matcher with the pre-existing ones.
@@ -293,7 +291,7 @@ fn generic_extension<'cx>(
293291
// Restore to the state before snapshotting and maybe try again.
294292
mem::swap(&mut gated_spans_snaphot, &mut cx.parse_sess.gated_spans.spans.borrow_mut());
295293
}
296-
drop(base_parser);
294+
drop(parser);
297295

298296
let (token, label) = best_failure.expect("ran no matchers");
299297
let span = token.span.substitute_dummy(sp);
@@ -311,9 +309,8 @@ fn generic_extension<'cx>(
311309
mbe::TokenTree::Delimited(_, ref delim) => &delim.tts[..],
312310
_ => continue,
313311
};
314-
let base_parser =
315-
base_parser_from_cx(&cx.current_expansion, &cx.parse_sess, arg.clone());
316-
match parse_tt(&mut Cow::Borrowed(&base_parser), lhs_tt) {
312+
let parser = parser_from_cx(&cx.current_expansion, &cx.parse_sess, arg.clone());
313+
match parse_tt(&mut Cow::Borrowed(&parser), lhs_tt) {
317314
Success(_) => {
318315
if comma_span.is_dummy() {
319316
err.note("you might be missing a comma");
@@ -395,8 +392,8 @@ pub fn compile_declarative_macro(
395392
),
396393
];
397394

398-
let base_parser = Parser::new(sess, body, None, true, true, rustc_parse::MACRO_ARGUMENTS);
399-
let argument_map = match parse_tt(&mut Cow::Borrowed(&base_parser), &argument_gram) {
395+
let parser = Parser::new(sess, body, None, true, true, rustc_parse::MACRO_ARGUMENTS);
396+
let argument_map = match parse_tt(&mut Cow::Borrowed(&parser), &argument_gram) {
400397
Success(m) => m,
401398
Failure(token, msg) => {
402399
let s = parse_failure_msg(&token);
@@ -1212,7 +1209,7 @@ fn quoted_tt_to_string(tt: &mbe::TokenTree) -> String {
12121209
}
12131210
}
12141211

1215-
fn base_parser_from_cx<'cx>(
1212+
fn parser_from_cx<'cx>(
12161213
current_expansion: &'cx ExpansionData,
12171214
sess: &'cx ParseSess,
12181215
tts: TokenStream,

0 commit comments

Comments
 (0)