Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Short-circuit precedence scan for high-precedence expressions #1838

Merged
merged 1 commit into from
Jan 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Short-circuit precedence scan for high-precedence expressions
  • Loading branch information
dtolnay committed Jan 10, 2025
commit 00a125eeeeb9f714bc55dcbe058985bedb636154
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
Loading