diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-02-01 05:54:39 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-02-01 05:54:39 +0100 |
| commit | 6390d25eab41efdbb96e6d42a67fd98d64469317 (patch) | |
| tree | 16a73c5eac8d2e2f5a099fb8c2936e20c1711fc0 | |
| parent | b853b22270c794e8f2b76e346173d9387cfff0c1 (diff) | |
| parent | e905b937060e3c920d85d1ae09d1e3a9a5f5a190 (diff) | |
| download | rust-6390d25eab41efdbb96e6d42a67fd98d64469317.tar.gz rust-6390d25eab41efdbb96e6d42a67fd98d64469317.zip | |
Rollup merge of #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 #107213. r? ```@estebank```
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 |
