Skip to content

Commit 275bf62

Browse files
committed
pretty-print-reparse hack: Rename some variables for clarity
1 parent 6f9a8a7 commit 275bf62

File tree

1 file changed

+21
-16
lines changed
  • compiler/rustc_parse/src

1 file changed

+21
-16
lines changed

compiler/rustc_parse/src/lib.rs

+21-16
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ pub fn nt_to_tokenstream(nt: &Nonterminal, sess: &ParseSess, span: Span) -> Toke
299299
// FIXME(#43081): Avoid this pretty-print + reparse hack
300300
let source = pprust::nonterminal_to_string(nt);
301301
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));
303303

304304
// During early phases of the compiler the AST could get modified
305305
// 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
325325
// modifications, including adding/removing typically non-semantic
326326
// tokens such as extra braces and commas, don't happen.
327327
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) {
329329
return tokens;
330330
}
331331
info!(
332332
"cached tokens found, but they're not \"probably equal\", \
333333
going with stringified version"
334334
);
335335
info!("cached tokens: {:?}", tokens);
336-
info!("reparsed tokens: {:?}", tokens_for_real);
336+
info!("reparsed tokens: {:?}", reparsed_tokens);
337337
}
338-
tokens_for_real
338+
reparsed_tokens
339339
}
340340

341341
// 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
344344
// This is otherwise the same as `eq_unspanned`, only recursing with a
345345
// different method.
346346
pub fn tokenstream_probably_equal_for_proc_macro(
347-
first: &TokenStream,
348-
other: &TokenStream,
347+
tokens: &TokenStream,
348+
reparsed_tokens: &TokenStream,
349349
sess: &ParseSess,
350350
) -> bool {
351351
// When checking for `probably_eq`, we ignore certain tokens that aren't
@@ -460,10 +460,11 @@ pub fn tokenstream_probably_equal_for_proc_macro(
460460

461461
// Break tokens after we expand any nonterminals, so that we break tokens
462462
// 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);
465466

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))
467468
}
468469

469470
// See comments in `Nonterminal::to_tokenstream` for why we care about
@@ -472,16 +473,20 @@ pub fn tokenstream_probably_equal_for_proc_macro(
472473
// This is otherwise the same as `eq_unspanned`, only recursing with a
473474
// different method.
474475
pub fn tokentree_probably_equal_for_proc_macro(
475-
first: &TokenTree,
476-
other: &TokenTree,
476+
token: &TokenTree,
477+
reparsed_token: &TokenTree,
477478
sess: &ParseSess,
478479
) -> 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)
482483
}
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)
485490
}
486491
_ => false,
487492
}

0 commit comments

Comments
 (0)