Skip to content

Commit

Permalink
Rollup merge of rust-lang#107487 - edward-shen:edward-shen/107213-rou…
Browse files Browse the repository at this point in the history
…nd-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``
  • Loading branch information
GuillaumeGomez authored Jan 31, 2023
2 parents 307a879 + e905b93 commit c4c989f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/let-else/accidental-if.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c4c989f

Please sign in to comment.