Minor improvement on else-no-if diagnostic
This commit is contained in:
parent
fa70b89d19
commit
d61d30d9a2
2 changed files with 3 additions and 18 deletions
|
@ -2291,16 +2291,9 @@ impl<'a> Parser<'a> {
|
||||||
.span_label(else_span, "expected an `if` or a block after this `else`")
|
.span_label(else_span, "expected an `if` or a block after this `else`")
|
||||||
.span_suggestion(
|
.span_suggestion(
|
||||||
cond.span.shrink_to_lo(),
|
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(),
|
"if ".to_string(),
|
||||||
Applicability::MaybeIncorrect,
|
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();
|
.emit();
|
||||||
self.parse_if_after_cond(AttrVec::new(), cond.span.shrink_to_lo(), cond)?
|
self.parse_if_after_cond(AttrVec::new(), cond.span.shrink_to_lo(), cond)?
|
||||||
|
|
|
@ -6,14 +6,10 @@ LL | } else false {
|
||||||
| |
|
| |
|
||||||
| expected an `if` or a block after this `else`
|
| 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 {
|
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`
|
error: expected `{`, found `falsy`
|
||||||
--> $DIR/else-no-if.rs:10:12
|
--> $DIR/else-no-if.rs:10:12
|
||||||
|
@ -23,14 +19,10 @@ LL | } else falsy() {
|
||||||
| |
|
| |
|
||||||
| expected an `if` or a block after this `else`
|
| 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() {
|
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`
|
error: expected `{`, found `falsy`
|
||||||
--> $DIR/else-no-if.rs:17:12
|
--> $DIR/else-no-if.rs:17:12
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue