From 2dc903f145b6109598241dffa9b34e7885bbbe1e Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 15 Sep 2023 12:45:15 -0600 Subject: [PATCH] Factor out function to add syn parens --- tests/test_precedence.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/test_precedence.rs b/tests/test_precedence.rs index 4394190469..4743e87de8 100644 --- a/tests/test_precedence.rs +++ b/tests/test_precedence.rs @@ -376,6 +376,14 @@ fn syn_brackets(syn_expr: syn::Expr) -> syn::Expr { struct ParenthesizeEveryExpr; + fn parenthesize(expr: Expr) -> Expr { + Expr::Paren(ExprParen { + attrs: Vec::new(), + expr: Box::new(expr), + paren_token: token::Paren::default(), + }) + } + fn needs_paren(expr: &Expr) -> bool { match expr { Expr::Group(_) => unreachable!(), @@ -399,11 +407,7 @@ fn syn_brackets(syn_expr: syn::Expr) -> syn::Expr { impl Fold for ParenthesizeEveryExpr { fn fold_expr(&mut self, expr: Expr) -> Expr { if needs_paren(&expr) { - Expr::Paren(ExprParen { - attrs: Vec::new(), - expr: Box::new(fold_expr(self, expr)), - paren_token: token::Paren::default(), - }) + parenthesize(fold_expr(self, expr)) } else { fold_expr(self, expr) }