Skip to content

Commit 1f096d3

Browse files
authored
Merge pull request #1839 from dtolnay/chainedcompare
Fix parenthesization of chained comparisons containing bailout
2 parents 9872bef + 4944362 commit 1f096d3

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/fixup.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,9 @@ fn scan_right(
547547
return Scan::Consume;
548548
}
549549
let binop_prec = Precedence::of_binop(&e.op);
550+
if binop_prec == Precedence::Compare && fixup.next_operator == Precedence::Compare {
551+
return Scan::Consume;
552+
}
550553
let right_fixup = fixup.rightmost_subexpression_fixup(false, false, binop_prec);
551554
let scan = scan_right(
552555
&e.right,
@@ -639,10 +642,13 @@ fn scan_right(
639642
Scan::Fail
640643
}
641644
}
642-
None => match fixup.next_operator {
643-
Precedence::Range => Scan::Consume,
644-
_ => Scan::Fail,
645-
},
645+
None => {
646+
if fixup.next_operator_can_begin_expr {
647+
Scan::Consume
648+
} else {
649+
Scan::Fail
650+
}
651+
}
646652
},
647653
Expr::Break(e) => match &e.expr {
648654
Some(value) => {

tests/test_expr.rs

+1
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,7 @@ fn test_fixup() {
799799
quote! { (1 + 1).abs() },
800800
quote! { (lo..hi)[..] },
801801
quote! { (a..b)..(c..d) },
802+
quote! { (x > ..) > x },
802803
quote! { (&mut fut).await },
803804
quote! { &mut (x as i32) },
804805
quote! { -(x as i32) },

0 commit comments

Comments
 (0)