From f6cd75fb1bb20d75fff2dba560a124fa1b10f1cd Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 6 Jul 2024 19:59:41 -0700 Subject: [PATCH] Parenthesize leading Expr::Let in statement --- src/fixup.rs | 1 + tests/test_expr.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/fixup.rs b/src/fixup.rs index 9423e36954..ddee906fb5 100644 --- a/src/fixup.rs +++ b/src/fixup.rs @@ -221,6 +221,7 @@ impl FixupContext { /// examples. pub fn would_cause_statement_boundary(self, expr: &Expr) -> bool { (self.leftmost_subexpression_in_stmt && !classify::requires_semi_to_be_stmt(expr)) + || ((self.stmt || self.leftmost_subexpression_in_stmt) && matches!(expr, Expr::Let(_))) || (self.leftmost_subexpression_in_match_arm && !classify::requires_comma_to_be_match_arm(expr)) } diff --git a/tests/test_expr.rs b/tests/test_expr.rs index 3849286431..11d0f86c50 100644 --- a/tests/test_expr.rs +++ b/tests/test_expr.rs @@ -680,6 +680,7 @@ fn test_fixup() { quote! { (..) = () }, quote! { (..) += () }, quote! { (1 < 2) == (3 < 4) }, + quote! { { (let _ = ()) } }, ] { let original: Expr = syn::parse2(tokens).unwrap();