Skip to content

Commit e905b93

Browse files
committed
Make the "extra if in let...else block" hint a suggestion
1 parent f55b002 commit e905b93

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

compiler/rustc_parse/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ pub(crate) enum IfExpressionMissingThenBlockSub {
351351
}
352352

353353
#[derive(Subdiagnostic)]
354-
#[help(parse_extra_if_in_let_else)]
354+
#[suggestion(parse_extra_if_in_let_else, applicability = "maybe-incorrect", code = "")]
355355
pub(crate) struct IfExpressionLetSomeSub {
356356
#[primary_span]
357357
pub if_span: Span,

compiler/rustc_parse/src/parser/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2281,7 +2281,7 @@ impl<'a> Parser<'a> {
22812281
block
22822282
} else {
22832283
let let_else_sub = matches!(cond.kind, ExprKind::Let(..))
2284-
.then(|| IfExpressionLetSomeSub { if_span: lo });
2284+
.then(|| IfExpressionLetSomeSub { if_span: lo.until(cond_span) });
22852285

22862286
self.sess.emit_err(IfExpressionMissingThenBlock {
22872287
if_span: lo,

tests/ui/let-else/accidental-if.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ help: add a block here
1010
LL | if let Some(y) = x else {
1111
| ^
1212
help: remove the `if` if you meant to write a `let...else` statement
13-
--> $DIR/accidental-if.rs:3:5
1413
|
15-
LL | if let Some(y) = x else {
16-
| ^^
14+
LL - if let Some(y) = x else {
15+
LL + let Some(y) = x else {
16+
|
1717

1818
error: aborting due to previous error
1919

tests/ui/rfc-2497-if-let-chains/ensure-that-let-else-does-not-interact-with-let-chains.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ help: add a block here
3838
LL | if let Some(n) = opt else {
3939
| ^
4040
help: remove the `if` if you meant to write a `let...else` statement
41-
--> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:24:5
4241
|
43-
LL | if let Some(n) = opt else {
44-
| ^^
42+
LL - if let Some(n) = opt else {
43+
LL + let Some(n) = opt else {
44+
|
4545

4646
error: this `if` expression is missing a block after the condition
4747
--> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:28:5

0 commit comments

Comments
 (0)