Skip to content

Provide a better error message for a common error of a missing do keyword #2785

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/rustc/middle/typeck/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down