Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2291,16 +2291,9 @@ impl<'a> Parser<'a> {
.span_label(else_span, "expected an `if` or a block after this `else`")
.span_suggestion(
cond.span.shrink_to_lo(),
"add an `if` if this is the condition to an chained `if` statement after the `else`",
"add an `if` if this is the condition of a chained `else if` statement",
"if ".to_string(),
Applicability::MaybeIncorrect,
).multipart_suggestion(
"... otherwise, place this expression inside of a block if it is not an `if` condition",
vec![
(cond.span.shrink_to_lo(), "{ ".to_string()),
(cond.span.shrink_to_hi(), " }".to_string()),
],
Applicability::MaybeIncorrect,
)
.emit();
self.parse_if_after_cond(AttrVec::new(), cond.span.shrink_to_lo(), cond)?
Expand Down
12 changes: 2 additions & 10 deletions src/test/ui/parser/else-no-if.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ LL | } else false {
| |
| expected an `if` or a block after this `else`
|
help: add an `if` if this is the condition to an chained `if` statement after the `else`
help: add an `if` if this is the condition of a chained `else if` statement
|
LL | } else if false {
| ++
help: ... otherwise, place this expression inside of a block if it is not an `if` condition
|
LL | } else { false } {
| + +

error: expected `{`, found `falsy`
--> $DIR/else-no-if.rs:10:12
Expand All @@ -23,14 +19,10 @@ LL | } else falsy() {
| |
| expected an `if` or a block after this `else`
|
help: add an `if` if this is the condition to an chained `if` statement after the `else`
help: add an `if` if this is the condition of a chained `else if` statement
|
LL | } else if falsy() {
| ++
help: ... otherwise, place this expression inside of a block if it is not an `if` condition
|
LL | } else { falsy() } {
| + +

error: expected `{`, found `falsy`
--> $DIR/else-no-if.rs:17:12
Expand Down