about summary refs log tree commit diff
path: root/src/rustc
diff options
context:
space:
mode:
authorMarijn Haverbeke <marijnh@gmail.com>2012-04-23 15:43:29 +0200
committerMarijn Haverbeke <marijnh@gmail.com>2012-04-23 15:43:29 +0200
commit2782cfb783129c1bf271cf31ac51f3a02d55c335 (patch)
treea97c2f16c6f1e984985361ac2b66ff3518bc300b /src/rustc
parent9053f54498373c8ca799e777d8a979c0d32fbb07 (diff)
downloadrust-2782cfb783129c1bf271cf31ac51f3a02d55c335.tar.gz
rust-2782cfb783129c1bf271cf31ac51f3a02d55c335.zip
Emit a more useful error when using an unsuitable function for a loop
Closes #2255
Diffstat (limited to 'src/rustc')
-rw-r--r--src/rustc/middle/typeck.rs17
1 files changed, 14 insertions, 3 deletions
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 {