Skip to content

Commit 5215ca4

Browse files
committed
Use Recovered more
1 parent f7c3ce7 commit 5215ca4

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

compiler/rustc_parse/src/parser/diagnostics.rs

+16-12
Original file line numberDiff line numberDiff line change
@@ -1288,15 +1288,15 @@ impl<'a> Parser<'a> {
12881288
err: &mut ComparisonOperatorsCannotBeChained,
12891289
inner_op: &Expr,
12901290
outer_op: &Spanned<AssocOp>,
1291-
) -> bool /* advanced the cursor */ {
1291+
) -> Recovered {
12921292
if let ExprKind::Binary(op, l1, r1) = &inner_op.kind {
12931293
if let ExprKind::Field(_, ident) = l1.kind
12941294
&& ident.as_str().parse::<i32>().is_err()
12951295
&& !matches!(r1.kind, ExprKind::Lit(_))
12961296
{
12971297
// The parser has encountered `foo.bar<baz`, the likelihood of the turbofish
12981298
// suggestion being the only one to apply is high.
1299-
return false;
1299+
return Recovered::No;
13001300
}
13011301
return match (op.node, &outer_op.node) {
13021302
// `x == y == z`
@@ -1315,7 +1315,7 @@ impl<'a> Parser<'a> {
13151315
span: inner_op.span.shrink_to_hi(),
13161316
middle_term: expr_to_str(r1),
13171317
});
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`.
13191319
}
13201320
// `x == y < z`
13211321
(BinOpKind::Eq, AssocOp::Less | AssocOp::LessEqual | AssocOp::Greater | AssocOp::GreaterEqual) => {
@@ -1329,12 +1329,12 @@ impl<'a> Parser<'a> {
13291329
left: r1.span.shrink_to_lo(),
13301330
right: r2.span.shrink_to_hi(),
13311331
});
1332-
true
1332+
Recovered::Yes
13331333
}
13341334
Err(expr_err) => {
13351335
expr_err.cancel();
13361336
self.restore_snapshot(snapshot);
1337-
false
1337+
Recovered::Yes
13381338
}
13391339
}
13401340
}
@@ -1349,19 +1349,19 @@ impl<'a> Parser<'a> {
13491349
left: l1.span.shrink_to_lo(),
13501350
right: r1.span.shrink_to_hi(),
13511351
});
1352-
true
1352+
Recovered::Yes
13531353
}
13541354
Err(expr_err) => {
13551355
expr_err.cancel();
13561356
self.restore_snapshot(snapshot);
1357-
false
1357+
Recovered::No
13581358
}
13591359
}
13601360
}
1361-
_ => false,
1361+
_ => Recovered::No,
13621362
};
13631363
}
1364-
false
1364+
Recovered::No
13651365
}
13661366

13671367
/// Produces an error if comparison operators are chained (RFC #558).
@@ -1489,8 +1489,12 @@ impl<'a> Parser<'a> {
14891489

14901490
// If it looks like a genuine attempt to chain operators (as opposed to a
14911491
// 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+
) {
14941498
self.dcx().emit_err(err);
14951499
mk_err_expr(self, inner_op.span.to(self.prev_token.span))
14961500
} else {
@@ -1502,7 +1506,7 @@ impl<'a> Parser<'a> {
15021506
let recover =
15031507
self.attempt_chained_comparison_suggestion(&mut err, inner_op, outer_op);
15041508
self.dcx().emit_err(err);
1505-
if recover {
1509+
if matches!(recover, Recovered::Yes) {
15061510
return mk_err_expr(self, inner_op.span.to(self.prev_token.span));
15071511
}
15081512
}

0 commit comments

Comments
 (0)