@@ -1288,15 +1288,15 @@ impl<'a> Parser<'a> {
1288
1288
err : & mut ComparisonOperatorsCannotBeChained ,
1289
1289
inner_op : & Expr ,
1290
1290
outer_op : & Spanned < AssocOp > ,
1291
- ) -> bool /* advanced the cursor */ {
1291
+ ) -> Recovered {
1292
1292
if let ExprKind :: Binary ( op, l1, r1) = & inner_op. kind {
1293
1293
if let ExprKind :: Field ( _, ident) = l1. kind
1294
1294
&& ident. as_str ( ) . parse :: < i32 > ( ) . is_err ( )
1295
1295
&& !matches ! ( r1. kind, ExprKind :: Lit ( _) )
1296
1296
{
1297
1297
// The parser has encountered `foo.bar<baz`, the likelihood of the turbofish
1298
1298
// suggestion being the only one to apply is high.
1299
- return false ;
1299
+ return Recovered :: No ;
1300
1300
}
1301
1301
return match ( op. node , & outer_op. node ) {
1302
1302
// `x == y == z`
@@ -1315,7 +1315,7 @@ impl<'a> Parser<'a> {
1315
1315
span : inner_op. span . shrink_to_hi ( ) ,
1316
1316
middle_term : expr_to_str ( r1) ,
1317
1317
} ) ;
1318
- false // Keep the current parse behavior, where the AST is `(x < y) < z`.
1318
+ Recovered :: No // Keep the current parse behavior, where the AST is `(x < y) < z`.
1319
1319
}
1320
1320
// `x == y < z`
1321
1321
( BinOpKind :: Eq , AssocOp :: Less | AssocOp :: LessEqual | AssocOp :: Greater | AssocOp :: GreaterEqual ) => {
@@ -1329,12 +1329,12 @@ impl<'a> Parser<'a> {
1329
1329
left : r1. span . shrink_to_lo ( ) ,
1330
1330
right : r2. span . shrink_to_hi ( ) ,
1331
1331
} ) ;
1332
- true
1332
+ Recovered :: Yes
1333
1333
}
1334
1334
Err ( expr_err) => {
1335
1335
expr_err. cancel ( ) ;
1336
1336
self . restore_snapshot ( snapshot) ;
1337
- false
1337
+ Recovered :: Yes
1338
1338
}
1339
1339
}
1340
1340
}
@@ -1349,19 +1349,19 @@ impl<'a> Parser<'a> {
1349
1349
left : l1. span . shrink_to_lo ( ) ,
1350
1350
right : r1. span . shrink_to_hi ( ) ,
1351
1351
} ) ;
1352
- true
1352
+ Recovered :: Yes
1353
1353
}
1354
1354
Err ( expr_err) => {
1355
1355
expr_err. cancel ( ) ;
1356
1356
self . restore_snapshot ( snapshot) ;
1357
- false
1357
+ Recovered :: No
1358
1358
}
1359
1359
}
1360
1360
}
1361
- _ => false ,
1361
+ _ => Recovered :: No ,
1362
1362
} ;
1363
1363
}
1364
- false
1364
+ Recovered :: No
1365
1365
}
1366
1366
1367
1367
/// Produces an error if comparison operators are chained (RFC #558).
@@ -1489,8 +1489,12 @@ impl<'a> Parser<'a> {
1489
1489
1490
1490
// If it looks like a genuine attempt to chain operators (as opposed to a
1491
1491
// misformatted turbofish, for instance), suggest a correct form.
1492
- if self . attempt_chained_comparison_suggestion ( & mut err, inner_op, outer_op)
1493
- {
1492
+ if matches ! (
1493
+ self . attempt_chained_comparison_suggestion(
1494
+ & mut err, inner_op, outer_op
1495
+ ) ,
1496
+ Recovered :: Yes
1497
+ ) {
1494
1498
self . dcx ( ) . emit_err ( err) ;
1495
1499
mk_err_expr ( self , inner_op. span . to ( self . prev_token . span ) )
1496
1500
} else {
@@ -1502,7 +1506,7 @@ impl<'a> Parser<'a> {
1502
1506
let recover =
1503
1507
self . attempt_chained_comparison_suggestion ( & mut err, inner_op, outer_op) ;
1504
1508
self . dcx ( ) . emit_err ( err) ;
1505
- if recover {
1509
+ if matches ! ( recover, Recovered :: Yes ) {
1506
1510
return mk_err_expr ( self , inner_op. span . to ( self . prev_token . span ) ) ;
1507
1511
}
1508
1512
}
0 commit comments