From f8f0f7b228a2587195863a62766cf6ba022447af Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Wed, 22 Apr 2020 11:57:40 -0400 Subject: [PATCH] Add help message for missing right operand in condition --- src/librustc_parse/parser/expr.rs | 5 +++++ src/test/ui/if/if-without-block.stderr | 2 ++ 2 files changed, 7 insertions(+) diff --git a/src/librustc_parse/parser/expr.rs b/src/librustc_parse/parser/expr.rs index 986f5410e26c0..85587b7733a20 100644 --- a/src/librustc_parse/parser/expr.rs +++ b/src/librustc_parse/parser/expr.rs @@ -1550,6 +1550,11 @@ impl<'a> Parser<'a> { let block = self.parse_block().map_err(|mut err| { if not_block { err.span_label(lo, "this `if` expression has a condition, but no block"); + if let ExprKind::Binary(_, _, ref right) = cond.kind { + if let ExprKind::Block(_, _) = right.kind { + err.help("maybe you forgot the right operand of the condition?"); + } + } } err })?; diff --git a/src/test/ui/if/if-without-block.stderr b/src/test/ui/if/if-without-block.stderr index 34df8e3d77946..ee2bb62e2bb57 100644 --- a/src/test/ui/if/if-without-block.stderr +++ b/src/test/ui/if/if-without-block.stderr @@ -6,6 +6,8 @@ LL | if 5 == { ... LL | } | ^ expected `{` + | + = help: maybe you forgot the right operand of the condition? error: aborting due to previous error