Skip to content

Commit

Permalink
Fix infinite loop on chained comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Sep 27, 2024
1 parent 3f3d0c5 commit b3d2886
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1284,7 +1284,7 @@ pub(crate) mod parsing {
if precedence == Precedence::Compare {
if let Expr::Binary(lhs) = &lhs {
if Precedence::of_binop(&lhs.op) == Precedence::Compare {
break;
return Err(input.error("comparison operators cannot be chained"));
}
}
}
Expand Down Expand Up @@ -1346,7 +1346,7 @@ pub(crate) mod parsing {
if precedence == Precedence::Compare {
if let Expr::Binary(lhs) = &lhs {
if Precedence::of_binop(&lhs.op) == Precedence::Compare {
break;
return Err(input.error("comparison operators cannot be chained"));
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions tests/test_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,9 @@ fn test_assign_range_precedence() {
fn test_chained_comparison() {
// https://github.com/dtolnay/syn/issues/1738
let _ = syn::parse_str::<Expr>("a = a < a <");

let err = syn::parse_str::<Expr>("a < a < a").unwrap_err();
assert_eq!("comparison operators cannot be chained", err.to_string());
}

#[test]
Expand Down

0 comments on commit b3d2886

Please sign in to comment.