about summary refs log tree commit diff
path: root/src/comp
diff options
context:
space:
mode:
authorTim Chevalier <chevalier@alum.wellesley.edu>2011-08-24 17:24:58 -0700
committerTim Chevalier <chevalier@alum.wellesley.edu>2011-08-25 17:23:35 -0700
commite241f2996dcf99f3d9fd2f9e277e435782c65a61 (patch)
treecc86000e235ab08c5b0ac9a3f3b719736df1d068 /src/comp
parent4dd23f24d65e05169594bfcb45b84adfe4e52516 (diff)
downloadrust-e241f2996dcf99f3d9fd2f9e277e435782c65a61.tar.gz
rust-e241f2996dcf99f3d9fd2f9e277e435782c65a61.zip
Allow pure fns to have any return type
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/middle/ty.rs7
-rw-r--r--src/comp/middle/typeck.rs19
2 files changed, 13 insertions, 13 deletions
diff --git a/src/comp/middle/ty.rs b/src/comp/middle/ty.rs
index 5d448825b89..e65265e640f 100644
--- a/src/comp/middle/ty.rs
+++ b/src/comp/middle/ty.rs
@@ -55,6 +55,7 @@ export hash_ty;
 export idx_nil;
 export is_lval;
 export is_binopable;
+export is_pred_ty;
 export item_table;
 export lookup_item_type;
 export method;
@@ -1737,6 +1738,12 @@ fn is_fn_ty(cx: &ctxt, fty: t) -> bool {
     }
 }
 
+// Just checks whether it's a fn that returns bool,
+// not its purity.
+fn is_pred_ty(cx: &ctxt, fty:t) -> bool {
+    is_fn_ty(cx, fty) && type_is_bool(cx, ty_fn_ret(cx, fty))
+}
+
 fn ty_var_id(cx: &ctxt, typ: t) -> int {
     alt struct(cx, typ) {
       ty::ty_var(vid) { ret vid; }
diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs
index f282c63861f..ad199ba5cb3 100644
--- a/src/comp/middle/typeck.rs
+++ b/src/comp/middle/typeck.rs
@@ -1715,6 +1715,11 @@ fn check_expr_with_unifier(fcx: &@fn_ctxt, expr: &@ast::expr, unify: &unifier,
            literals or slots */
         alt e.node {
           ast::expr_call(operator, operands) {
+            if !ty::is_pred_ty(fcx.ccx.tcx, expr_ty(fcx.ccx.tcx, operator)) {
+                    fcx.ccx.tcx.sess.span_fatal(operator.span,
+                     "Operator in constraint has non-boolean return type");
+            }
+
             alt operator.node {
               ast::expr_path(oper_name) {
                 alt fcx.ccx.tcx.def_map.find(operator.id) {
@@ -1723,7 +1728,7 @@ fn check_expr_with_unifier(fcx: &@fn_ctxt, expr: &@ast::expr, unify: &unifier,
                   }
                   _ {
                     fcx.ccx.tcx.sess.span_fatal(operator.span,
-                                                "non-predicate as operator \
+                                           "Impure function as operator \
                                        in constraint");
                   }
                 }
@@ -2596,18 +2601,6 @@ fn check_fn(ccx: &@crate_ctxt, f: &ast::_fn, id: &ast::node_id,
           mutable fixups: fixups,
           ccx: ccx};
     check_block(fcx, body);
-    alt decl.purity {
-      ast::pure_fn. {
-
-        // This just checks that the declared type is bool, and trusts
-        // that that's the actual return type.
-        if !ty::type_is_bool(ccx.tcx, fcx.ret_ty) {
-            ccx.tcx.sess.span_err(body.span,
-                                  "Non-boolean return type in pred");
-        }
-      }
-      _ { }
-    }
 
     // For non-iterator fns, we unify the tail expr's type with the
     // function result type, if there is a tail expr.