From 0447e61ae42ef48089b774974da4b75936eaf36d Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Tue, 3 Jul 2012 00:42:59 +0100 Subject: [PATCH] Provide a better error message for a common error of a missing do keyword. Closes #2783 --- src/rustc/middle/typeck/check.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/rustc/middle/typeck/check.rs b/src/rustc/middle/typeck/check.rs index aac959b4cb456..9a29226a2d3d6 100644 --- a/src/rustc/middle/typeck/check.rs +++ b/src/rustc/middle/typeck/check.rs @@ -973,11 +973,25 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, _ {} } check_expr(fcx, rhs, none); + + let mut extra = ""; + + // If the or operator is used it might be that the user forgot to + // supply the do keyword. Let's be more helpful in that situation. + if op == ast::or { + alt ty::get(lhs_resolved_t).struct { + ty::ty_fn(f) { + extra = ". Did you forget the 'do' keyword for the call?"; + } + _ {} + } + } + tcx.sess.span_err( ex.span, "binary operation " + ast_util::binop_to_str(op) + " cannot be applied to type `" + fcx.infcx.ty_to_str(lhs_resolved_t) + - "`"); + "`" + extra); (lhs_resolved_t, false) } fn check_user_unop(fcx: @fn_ctxt, op_str: str, mname: str,