Skip to content

Commit 1e64a38

Browse files
Rollup merge of rust-lang#107487 - edward-shen:edward-shen/107213-round-2, r=estebank
Make the "extra if in let...else block" hint a suggestion Changes the hint to a suggestion, suggested in rust-lang#107213. r? `@estebank`
2 parents 7e107b3 + e905b93 commit 1e64a38

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

compiler/rustc_parse/src/errors.rs

+1-1
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -2290,7 +2290,7 @@ impl<'a> Parser<'a> {
22902290
block
22912291
} else {
22922292
let let_else_sub = matches!(cond.kind, ExprKind::Let(..))
2293-
.then(|| IfExpressionLetSomeSub { if_span: lo });
2293+
.then(|| IfExpressionLetSomeSub { if_span: lo.until(cond_span) });
22942294

22952295
self.sess.emit_err(IfExpressionMissingThenBlock {
22962296
if_span: lo,

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

+3-3
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

+3-3
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)