@@ -299,7 +299,7 @@ pub fn nt_to_tokenstream(nt: &Nonterminal, sess: &ParseSess, span: Span) -> Toke
299
299
// FIXME(#43081): Avoid this pretty-print + reparse hack
300
300
let source = pprust:: nonterminal_to_string ( nt) ;
301
301
let filename = FileName :: macro_expansion_source_code ( & source) ;
302
- let tokens_for_real = parse_stream_from_source_str ( filename, source, sess, Some ( span) ) ;
302
+ let reparsed_tokens = parse_stream_from_source_str ( filename, source, sess, Some ( span) ) ;
303
303
304
304
// During early phases of the compiler the AST could get modified
305
305
// directly (e.g., attributes added or removed) and the internal cache
@@ -325,17 +325,17 @@ pub fn nt_to_tokenstream(nt: &Nonterminal, sess: &ParseSess, span: Span) -> Toke
325
325
// modifications, including adding/removing typically non-semantic
326
326
// tokens such as extra braces and commas, don't happen.
327
327
if let Some ( tokens) = tokens {
328
- if tokenstream_probably_equal_for_proc_macro ( & tokens, & tokens_for_real , sess) {
328
+ if tokenstream_probably_equal_for_proc_macro ( & tokens, & reparsed_tokens , sess) {
329
329
return tokens;
330
330
}
331
331
info ! (
332
332
"cached tokens found, but they're not \" probably equal\" , \
333
333
going with stringified version"
334
334
) ;
335
335
info ! ( "cached tokens: {:?}" , tokens) ;
336
- info ! ( "reparsed tokens: {:?}" , tokens_for_real ) ;
336
+ info ! ( "reparsed tokens: {:?}" , reparsed_tokens ) ;
337
337
}
338
- tokens_for_real
338
+ reparsed_tokens
339
339
}
340
340
341
341
// See comments in `Nonterminal::to_tokenstream` for why we care about
@@ -344,8 +344,8 @@ pub fn nt_to_tokenstream(nt: &Nonterminal, sess: &ParseSess, span: Span) -> Toke
344
344
// This is otherwise the same as `eq_unspanned`, only recursing with a
345
345
// different method.
346
346
pub fn tokenstream_probably_equal_for_proc_macro (
347
- first : & TokenStream ,
348
- other : & TokenStream ,
347
+ tokens : & TokenStream ,
348
+ reparsed_tokens : & TokenStream ,
349
349
sess : & ParseSess ,
350
350
) -> bool {
351
351
// When checking for `probably_eq`, we ignore certain tokens that aren't
@@ -460,10 +460,11 @@ pub fn tokenstream_probably_equal_for_proc_macro(
460
460
461
461
// Break tokens after we expand any nonterminals, so that we break tokens
462
462
// that are produced as a result of nonterminal expansion.
463
- let t1 = first. trees ( ) . filter ( semantic_tree) . flat_map ( expand_nt) . flat_map ( break_tokens) ;
464
- let t2 = other. trees ( ) . filter ( semantic_tree) . flat_map ( expand_nt) . flat_map ( break_tokens) ;
463
+ let tokens = tokens. trees ( ) . filter ( semantic_tree) . flat_map ( expand_nt) . flat_map ( break_tokens) ;
464
+ let reparsed_tokens =
465
+ reparsed_tokens. trees ( ) . filter ( semantic_tree) . flat_map ( expand_nt) . flat_map ( break_tokens) ;
465
466
466
- t1 . eq_by ( t2 , |t1 , t2 | tokentree_probably_equal_for_proc_macro ( & t1 , & t2 , sess) )
467
+ tokens . eq_by ( reparsed_tokens , |t , rt | tokentree_probably_equal_for_proc_macro ( & t , & rt , sess) )
467
468
}
468
469
469
470
// See comments in `Nonterminal::to_tokenstream` for why we care about
@@ -472,16 +473,20 @@ pub fn tokenstream_probably_equal_for_proc_macro(
472
473
// This is otherwise the same as `eq_unspanned`, only recursing with a
473
474
// different method.
474
475
pub fn tokentree_probably_equal_for_proc_macro (
475
- first : & TokenTree ,
476
- other : & TokenTree ,
476
+ token : & TokenTree ,
477
+ reparsed_token : & TokenTree ,
477
478
sess : & ParseSess ,
478
479
) -> bool {
479
- match ( first , other ) {
480
- ( TokenTree :: Token ( token) , TokenTree :: Token ( token2 ) ) => {
481
- token_probably_equal_for_proc_macro ( token, token2 )
480
+ match ( token , reparsed_token ) {
481
+ ( TokenTree :: Token ( token) , TokenTree :: Token ( reparsed_token ) ) => {
482
+ token_probably_equal_for_proc_macro ( token, reparsed_token )
482
483
}
483
- ( TokenTree :: Delimited ( _, delim, tts) , TokenTree :: Delimited ( _, delim2, tts2) ) => {
484
- delim == delim2 && tokenstream_probably_equal_for_proc_macro ( & tts, & tts2, sess)
484
+ (
485
+ TokenTree :: Delimited ( _, delim, tokens) ,
486
+ TokenTree :: Delimited ( _, reparsed_delim, reparsed_tokens) ,
487
+ ) => {
488
+ delim == reparsed_delim
489
+ && tokenstream_probably_equal_for_proc_macro ( tokens, reparsed_tokens, sess)
485
490
}
486
491
_ => false ,
487
492
}
0 commit comments