From 78f8f79069c14edff34009c08b2011b93b9fc3e4 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 10 Dec 2023 11:33:27 -0800 Subject: [PATCH] Improve variable naming in precedence test --- tests/test_precedence.rs | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/tests/test_precedence.rs b/tests/test_precedence.rs index fe47d0955d..c74a19988f 100644 --- a/tests/test_precedence.rs +++ b/tests/test_precedence.rs @@ -39,7 +39,7 @@ extern crate thin_vec; use crate::common::eq::SpanlessEq; use crate::common::parse; -use quote::quote; +use quote::ToTokens; use rustc_ast::ast; use rustc_ast::ptr::P; use rustc_ast_pretty::pprust; @@ -116,18 +116,20 @@ fn test_expressions(path: &Path, edition: Edition, exprs: Vec) -> (us rustc_span::create_session_if_not_set_then(edition, |_| { for expr in exprs { - let raw = quote!(#expr).to_string(); - - let librustc_ast = if let Some(e) = librustc_parse_and_rewrite(&raw) { + let source_code = expr.to_token_stream().to_string(); + let librustc_ast = if let Some(e) = librustc_parse_and_rewrite(&source_code) { e } else { failed += 1; - errorf!("\nFAIL {} - librustc failed to parse raw\n", path.display()); + errorf!( + "\nFAIL {} - librustc failed to parse original\n", + path.display(), + ); continue; }; - let syn_expr = syn_parenthesize(expr); - let syn_ast = if let Some(e) = parse::librustc_expr("e!(#syn_expr).to_string()) { + let syn_parenthesized_code = syn_parenthesize(expr).to_token_stream().to_string(); + let syn_ast = if let Some(e) = parse::librustc_expr(&syn_parenthesized_code) { e } else { failed += 1; @@ -142,13 +144,13 @@ fn test_expressions(path: &Path, edition: Edition, exprs: Vec) -> (us passed += 1; } else { failed += 1; - let syn_program = pprust::expr_to_string(&syn_ast); - let librustc_program = pprust::expr_to_string(&librustc_ast); + let syn_pretty = pprust::expr_to_string(&syn_ast); + let librustc_pretty = pprust::expr_to_string(&librustc_ast); errorf!( "\nFAIL {}\n{}\nsyn != rustc\n{}\n", path.display(), - syn_program, - librustc_program, + syn_pretty, + librustc_pretty, ); } }