From 00a125eeeeb9f714bc55dcbe058985bedb636154 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Thu, 9 Jan 2025 17:02:10 -0800 Subject: [PATCH] Short-circuit precedence scan for high-precedence expressions --- src/fixup.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/fixup.rs b/src/fixup.rs index ea382657d..9414d8384 100644 --- a/src/fixup.rs +++ b/src/fixup.rs @@ -351,9 +351,15 @@ impl FixupContext { let default_prec = self.precedence(expr); #[cfg(feature = "full")] - if default_prec < Precedence::Prefix - && (!self.next_operator_can_begin_expr || self.next_operator == Precedence::Range) - { + if match self.previous_operator { + Precedence::Assign | Precedence::Let | Precedence::Prefix => { + default_prec < self.previous_operator + } + _ => default_prec <= self.previous_operator, + } && match self.next_operator { + Precedence::Range => true, + _ => !self.next_operator_can_begin_expr, + } { if let Scan::Bailout | Scan::Fail = scan_right(expr, self, self.previous_operator, 1, 0) { if scan_left(expr, self) {