Skip to content

Commit

Permalink
Merge pull request #1838 from dtolnay/prevoperator
Browse files Browse the repository at this point in the history
Short-circuit precedence scan for high-precedence expressions
  • Loading branch information
dtolnay authored Jan 10, 2025
2 parents 83195c0 + 00a125e commit 9872bef
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/fixup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 9872bef

Please sign in to comment.