File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -1284,7 +1284,7 @@ pub(crate) mod parsing {
1284
1284
if precedence == Precedence :: Compare {
1285
1285
if let Expr :: Binary ( lhs) = & lhs {
1286
1286
if Precedence :: of_binop ( & lhs. op ) == Precedence :: Compare {
1287
- break ;
1287
+ return Err ( input . error ( "comparison operators cannot be chained" ) ) ;
1288
1288
}
1289
1289
}
1290
1290
}
@@ -1346,7 +1346,7 @@ pub(crate) mod parsing {
1346
1346
if precedence == Precedence :: Compare {
1347
1347
if let Expr :: Binary ( lhs) = & lhs {
1348
1348
if Precedence :: of_binop ( & lhs. op ) == Precedence :: Compare {
1349
- break ;
1349
+ return Err ( input . error ( "comparison operators cannot be chained" ) ) ;
1350
1350
}
1351
1351
}
1352
1352
}
Original file line number Diff line number Diff line change @@ -642,6 +642,15 @@ fn test_assign_range_precedence() {
642
642
syn:: parse_str :: < Expr > ( "() .. () += ()" ) . unwrap_err ( ) ;
643
643
}
644
644
645
+ #[ test]
646
+ fn test_chained_comparison ( ) {
647
+ // https://github.com/dtolnay/syn/issues/1738
648
+ let _ = syn:: parse_str :: < Expr > ( "a = a < a <" ) ;
649
+
650
+ let err = syn:: parse_str :: < Expr > ( "a < a < a" ) . unwrap_err ( ) ;
651
+ assert_eq ! ( "comparison operators cannot be chained" , err. to_string( ) ) ;
652
+ }
653
+
645
654
#[ test]
646
655
fn test_fixup ( ) {
647
656
struct FlattenParens ;
You can’t perform that action at this time.
0 commit comments