Skip to content

Commit 5bd9d6e

Browse files
mitsuhikobrson
authored andcommitted
Implemented better error message for missing do statements.
This fixes #2783 for the case where an empty double pipe symbol is being used without a do keyword.
1 parent 1bd4e35 commit 5bd9d6e

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/rustc/middle/typeck/check.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,11 +973,25 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
973973
_ {}
974974
}
975975
check_expr(fcx, rhs, none);
976+
976977
tcx.sess.span_err(
977978
ex.span, "binary operation " + ast_util::binop_to_str(op) +
978979
" cannot be applied to type `" +
979980
fcx.infcx.ty_to_str(lhs_resolved_t) +
980981
"`");
982+
983+
// If the or operator is used it might be that the user forgot to
984+
// supply the do keyword. Let's be more helpful in that situation.
985+
if op == ast::or {
986+
alt ty::get(lhs_resolved_t).struct {
987+
ty::ty_fn(f) {
988+
tcx.sess.span_note(
989+
ex.span, "did you forget the 'do' keyword for the call?");
990+
}
991+
_ {}
992+
}
993+
}
994+
981995
(lhs_resolved_t, false)
982996
}
983997
fn check_user_unop(fcx: @fn_ctxt, op_str: str, mname: str,

0 commit comments

Comments
 (0)