Skip to content

Commit f8f0f7b

Browse files
committed
Add help message for missing right operand in condition
1 parent 45d050c commit f8f0f7b

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/librustc_parse/parser/expr.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1550,6 +1550,11 @@ impl<'a> Parser<'a> {
15501550
let block = self.parse_block().map_err(|mut err| {
15511551
if not_block {
15521552
err.span_label(lo, "this `if` expression has a condition, but no block");
1553+
if let ExprKind::Binary(_, _, ref right) = cond.kind {
1554+
if let ExprKind::Block(_, _) = right.kind {
1555+
err.help("maybe you forgot the right operand of the condition?");
1556+
}
1557+
}
15531558
}
15541559
err
15551560
})?;

src/test/ui/if/if-without-block.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ LL | if 5 == {
66
...
77
LL | }
88
| ^ expected `{`
9+
|
10+
= help: maybe you forgot the right operand of the condition?
911

1012
error: aborting due to previous error
1113

0 commit comments

Comments
 (0)