@@ -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 [ ..] ,
@@ -224,13 +222,14 @@ fn generic_extension<'cx>(
224222 // This is used so that if a matcher is not `Success(..)`ful,
225223 // then the spans which became gated when parsing the unsuccessful matcher
226224 // are not recorded. On the first `Success(..)`ful matcher, the spans are merged.
227- let mut gated_spans_snaphot = mem:: take ( & mut * cx. parse_sess . gated_spans . spans . borrow_mut ( ) ) ;
225+ let mut gated_spans_snapshot =
226+ mem:: take ( & mut * cx. parse_sess . gated_spans . spans . borrow_mut ( ) ) ;
228227
229- match parse_tt ( & mut parser, lhs_tt) {
228+ match parse_tt ( & mut Cow :: Borrowed ( & parser) , lhs_tt) {
230229 Success ( named_matches) => {
231230 // The matcher was `Success(..)`ful.
232231 // Merge the gated spans from parsing the matcher with the pre-existing ones.
233- cx. parse_sess . gated_spans . merge ( gated_spans_snaphot ) ;
232+ cx. parse_sess . gated_spans . merge ( gated_spans_snapshot ) ;
234233
235234 let rhs = match rhses[ i] {
236235 // ignore delimiters
@@ -291,9 +290,9 @@ fn generic_extension<'cx>(
291290
292291 // The matcher was not `Success(..)`ful.
293292 // Restore to the state before snapshotting and maybe try again.
294- mem:: swap ( & mut gated_spans_snaphot , & mut cx. parse_sess . gated_spans . spans . borrow_mut ( ) ) ;
293+ mem:: swap ( & mut gated_spans_snapshot , & mut cx. parse_sess . gated_spans . spans . borrow_mut ( ) ) ;
295294 }
296- drop ( base_parser ) ;
295+ drop ( parser ) ;
297296
298297 let ( token, label) = best_failure. expect ( "ran no matchers" ) ;
299298 let span = token. span . substitute_dummy ( sp) ;
@@ -311,9 +310,8 @@ fn generic_extension<'cx>(
311310 mbe:: TokenTree :: Delimited ( _, ref delim) => & delim. tts [ ..] ,
312311 _ => continue ,
313312 } ;
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) {
313+ let parser = parser_from_cx ( & cx. current_expansion , & cx. parse_sess , arg. clone ( ) ) ;
314+ match parse_tt ( & mut Cow :: Borrowed ( & parser) , lhs_tt) {
317315 Success ( _) => {
318316 if comma_span. is_dummy ( ) {
319317 err. note ( "you might be missing a comma" ) ;
@@ -395,8 +393,8 @@ pub fn compile_declarative_macro(
395393 ) ,
396394 ] ;
397395
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) {
396+ let parser = Parser :: new ( sess, body, None , true , true , rustc_parse:: MACRO_ARGUMENTS ) ;
397+ let argument_map = match parse_tt ( & mut Cow :: Borrowed ( & parser ) , & argument_gram) {
400398 Success ( m) => m,
401399 Failure ( token, msg) => {
402400 let s = parse_failure_msg ( & token) ;
@@ -1212,7 +1210,7 @@ fn quoted_tt_to_string(tt: &mbe::TokenTree) -> String {
12121210 }
12131211}
12141212
1215- fn base_parser_from_cx < ' cx > (
1213+ fn parser_from_cx < ' cx > (
12161214 current_expansion : & ' cx ExpansionData ,
12171215 sess : & ' cx ParseSess ,
12181216 tts : TokenStream ,
0 commit comments