@@ -191,9 +191,9 @@ fn generic_extension<'cx>(
191
191
let mut best_failure: Option < ( Token , & str ) > = None ;
192
192
193
193
// 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:
197
197
//
198
198
// macro_rules! foo {
199
199
// ("a") => (A);
@@ -209,11 +209,9 @@ fn generic_extension<'cx>(
209
209
// hacky, but speeds up the `html5ever` benchmark significantly. (Issue
210
210
// 68836 suggests a more comprehensive but more complex change to deal with
211
211
// 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 ( ) ) ;
213
213
214
214
for ( i, lhs) in lhses. iter ( ) . enumerate ( ) {
215
- let mut parser = Cow :: Borrowed ( & base_parser) ;
216
-
217
215
// try each arm's matchers
218
216
let lhs_tt = match * lhs {
219
217
mbe:: TokenTree :: Delimited ( _, ref delim) => & delim. tts [ ..] ,
@@ -224,13 +222,14 @@ fn generic_extension<'cx>(
224
222
// This is used so that if a matcher is not `Success(..)`ful,
225
223
// then the spans which became gated when parsing the unsuccessful matcher
226
224
// 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 ( ) ) ;
228
227
229
- match parse_tt ( & mut parser, lhs_tt) {
228
+ match parse_tt ( & mut Cow :: Borrowed ( & parser) , lhs_tt) {
230
229
Success ( named_matches) => {
231
230
// The matcher was `Success(..)`ful.
232
231
// 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 ) ;
234
233
235
234
let rhs = match rhses[ i] {
236
235
// ignore delimiters
@@ -291,9 +290,9 @@ fn generic_extension<'cx>(
291
290
292
291
// The matcher was not `Success(..)`ful.
293
292
// 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 ( ) ) ;
295
294
}
296
- drop ( base_parser ) ;
295
+ drop ( parser ) ;
297
296
298
297
let ( token, label) = best_failure. expect ( "ran no matchers" ) ;
299
298
let span = token. span . substitute_dummy ( sp) ;
@@ -311,9 +310,8 @@ fn generic_extension<'cx>(
311
310
mbe:: TokenTree :: Delimited ( _, ref delim) => & delim. tts [ ..] ,
312
311
_ => continue ,
313
312
} ;
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) {
317
315
Success ( _) => {
318
316
if comma_span. is_dummy ( ) {
319
317
err. note ( "you might be missing a comma" ) ;
@@ -395,8 +393,8 @@ pub fn compile_declarative_macro(
395
393
) ,
396
394
] ;
397
395
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) {
400
398
Success ( m) => m,
401
399
Failure ( token, msg) => {
402
400
let s = parse_failure_msg ( & token) ;
@@ -1212,7 +1210,7 @@ fn quoted_tt_to_string(tt: &mbe::TokenTree) -> String {
1212
1210
}
1213
1211
}
1214
1212
1215
- fn base_parser_from_cx < ' cx > (
1213
+ fn parser_from_cx < ' cx > (
1216
1214
current_expansion : & ' cx ExpansionData ,
1217
1215
sess : & ' cx ParseSess ,
1218
1216
tts : TokenStream ,
0 commit comments