Skip to content

Commit be3faf3

Browse files
authored
Rollup merge of #71433 - antoyo:error/missing-right-operand, r=Dylan-DPC
Add help message for missing right operand in condition closes #30035
2 parents 09f3c90 + f8f0f7b commit be3faf3

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/librustc_parse/parser/expr.rs

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

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

Lines changed: 2 additions & 0 deletions
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)