about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_parse/src/errors.rs2
-rw-r--r--compiler/rustc_parse/src/parser/expr.rs2
-rw-r--r--tests/ui/let-else/accidental-if.stderr6
-rw-r--r--tests/ui/rfc-2497-if-let-chains/ensure-that-let-else-does-not-interact-with-let-chains.stderr6
4 files changed, 8 insertions, 8 deletions
diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs
index 054b41b478d..e63fc3c73b2 100644
--- a/compiler/rustc_parse/src/errors.rs
+++ b/compiler/rustc_parse/src/errors.rs
@@ -351,7 +351,7 @@ pub(crate) enum IfExpressionMissingThenBlockSub {
 }
 
 #[derive(Subdiagnostic)]
-#[help(parse_extra_if_in_let_else)]
+#[suggestion(parse_extra_if_in_let_else, applicability = "maybe-incorrect", code = "")]
 pub(crate) struct IfExpressionLetSomeSub {
     #[primary_span]
     pub if_span: Span,
diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs
index dcc3059a7f4..500d7d77071 100644
--- a/compiler/rustc_parse/src/parser/expr.rs
+++ b/compiler/rustc_parse/src/parser/expr.rs
@@ -2290,7 +2290,7 @@ impl<'a> Parser<'a> {
                 block
             } else {
                 let let_else_sub = matches!(cond.kind, ExprKind::Let(..))
-                    .then(|| IfExpressionLetSomeSub { if_span: lo });
+                    .then(|| IfExpressionLetSomeSub { if_span: lo.until(cond_span) });
 
                 self.sess.emit_err(IfExpressionMissingThenBlock {
                     if_span: lo,
diff --git a/tests/ui/let-else/accidental-if.stderr b/tests/ui/let-else/accidental-if.stderr
index 5474a67aac4..57e52591730 100644
--- a/tests/ui/let-else/accidental-if.stderr
+++ b/tests/ui/let-else/accidental-if.stderr
@@ -10,10 +10,10 @@ help: add a block here
 LL |     if let Some(y) = x else {
    |                       ^
 help: remove the `if` if you meant to write a `let...else` statement
-  --> $DIR/accidental-if.rs:3:5
    |
-LL |     if let Some(y) = x else {
-   |     ^^
+LL -     if let Some(y) = x else {
+LL +     let Some(y) = x else {
+   |
 
 error: aborting due to previous error
 
diff --git a/tests/ui/rfc-2497-if-let-chains/ensure-that-let-else-does-not-interact-with-let-chains.stderr b/tests/ui/rfc-2497-if-let-chains/ensure-that-let-else-does-not-interact-with-let-chains.stderr
index 80292845270..9bc3e754126 100644
--- a/tests/ui/rfc-2497-if-let-chains/ensure-that-let-else-does-not-interact-with-let-chains.stderr
+++ b/tests/ui/rfc-2497-if-let-chains/ensure-that-let-else-does-not-interact-with-let-chains.stderr
@@ -38,10 +38,10 @@ help: add a block here
 LL |     if let Some(n) = opt else {
    |                         ^
 help: remove the `if` if you meant to write a `let...else` statement
-  --> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:24:5
    |
-LL |     if let Some(n) = opt else {
-   |     ^^
+LL -     if let Some(n) = opt else {
+LL +     let Some(n) = opt else {
+   |
 
 error: this `if` expression is missing a block after the condition
   --> $DIR/ensure-that-let-else-does-not-interact-with-let-chains.rs:28:5