diff --git a/src/rustc/middle/typeck.rs b/src/rustc/middle/typeck.rs index 35fa0bed980..1560a9f469a 100644 --- a/src/rustc/middle/typeck.rs +++ b/src/rustc/middle/typeck.rs @@ -3305,9 +3305,20 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, let rty = structurally_resolved_type(fcx, expr.span, expected); let (inner_ty, proto) = alt check ty::get(rty).struct { ty::ty_fn(fty) { - demand::suptype(fcx, expr.span, fty.output, ty::mk_bool(tcx)); - (ty::mk_fn(tcx, {output: ty::mk_nil(tcx) with fty}), - fty.proto) + alt infer::mk_subty(fcx.infcx, fty.output, ty::mk_bool(tcx)) { + result::ok(_) {} + result::err(err) { + tcx.sess.span_fatal( + expr.span, #fmt("a loop function's last argument should \ + return `bool`, not `%s`", + ty_to_str(tcx, fty.output))); + } + } + (ty::mk_fn(tcx, {output: ty::mk_nil(tcx) with fty}), fty.proto) + } + _ { + tcx.sess.span_fatal(expr.span, "a loop function's last argument \ + should be of function type"); } }; alt check b.node { diff --git a/src/test/compile-fail/bad-for-loop.rs b/src/test/compile-fail/bad-for-loop.rs new file mode 100644 index 00000000000..a28d893b97e --- /dev/null +++ b/src/test/compile-fail/bad-for-loop.rs @@ -0,0 +1,4 @@ +fn main() { + fn baz(_x: fn() -> int) {} + for baz {|_e| } //! ERROR should return `bool` +} diff --git a/src/test/compile-fail/block-must-not-have-result-for.rs b/src/test/compile-fail/block-must-not-have-result-for.rs index c9f93301278..e4830ea519e 100644 --- a/src/test/compile-fail/block-must-not-have-result-for.rs +++ b/src/test/compile-fail/block-must-not-have-result-for.rs @@ -1,7 +1,7 @@ // error-pattern:mismatched types: expected `()` but found `bool` fn main() { - for vec::iter([0]) {|_i| + for vec::each([0]) {|_i| true } } \ No newline at end of file