Skip to content

Commit

Permalink
Implemented better error message for missing do statements.
Browse files Browse the repository at this point in the history
This fixes #2783 for the case where an empty double pipe
symbol is being used without a do keyword.
  • Loading branch information
mitsuhiko authored and brson committed Jul 3, 2012
1 parent 1bd4e35 commit 5bd9d6e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/rustc/middle/typeck/check.rs
Expand Up @@ -973,11 +973,25 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
_ {}
}
check_expr(fcx, rhs, none);

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) +
"`");

// 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) {
tcx.sess.span_note(
ex.span, "did you forget the 'do' keyword for the call?");
}
_ {}
}
}

(lhs_resolved_t, false)
}
fn check_user_unop(fcx: @fn_ctxt, op_str: str, mname: str,
Expand Down

3 comments on commit 5bd9d6e

@kud1ing
Copy link

@kud1ing kud1ing commented on 5bd9d6e Jul 3, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Two thoughts: do should be in back-ticks. And i would rephrase it to something like "Maybe a do is missing?" which would read less alleging. Maybe the user did write "do" but it got removed accidentally by a merge for example.

@lkuper
Copy link
Contributor

@lkuper lkuper commented on 5bd9d6e Jul 3, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for "perhaps a do is missing?"

@brson
Copy link
Contributor

@brson brson commented on 5bd9d6e Jul 3, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's also the possibility that they want a for instead of do.

Please sign in to comment.