]> git.lizzy.rs Git - rust.git/commitdiff
Make ty_fn_ret pure and get rid of a duplicate function
authorTim Chevalier <chevalier@alum.wellesley.edu>
Fri, 16 Sep 2011 20:03:11 +0000 (13:03 -0700)
committerTim Chevalier <chevalier@alum.wellesley.edu>
Fri, 16 Sep 2011 20:06:31 +0000 (13:06 -0700)
src/comp/middle/ty.rs

index a71811fccf74dabe66e2429974131ea7ef9f3385..f97bbd68f52ba73af90d35360cfa4cdd361ce0e0 100644 (file)
@@ -92,7 +92,6 @@
 export cname;
 export rename;
 export ret_ty_of_fn;
-export ret_ty_of_fn_ty;
 export sequence_element_type;
 export struct;
 export sort_methods;
@@ -1600,11 +1599,21 @@ fn ty_fn_abi(cx: ctxt, fty: t) -> ast::native_abi {
     }
 }
 
-fn ty_fn_ret(cx: ctxt, fty: t) -> t {
-    alt struct(cx, fty) {
+pure fn ty_fn_ret(cx: ctxt, fty: t) -> t {
+    // Should be pure, as type interner contents
+    // shouldn't change once set...
+    let sty = unchecked { struct(cx, fty) };
+    alt sty {
       ty::ty_fn(_, _, r, _, _) { ret r; }
       ty::ty_native_fn(_, _, r) { ret r; }
-      _ { cx.sess.bug("ty_fn_ret() called on non-fn type"); }
+      _ {
+        // Unchecked is ok since we diverge here
+        // (might want to change the typechecker to allow
+        // it without an unchecked)
+        // Or, it wouldn't be necessary if we had the right
+        // typestate constraint on cx and t (then we could
+        // call unreachable() instead)
+        unchecked { cx.sess.bug("ty_fn_ret() called on non-fn type"); }}
     }
 }
 
@@ -2634,19 +2643,8 @@ fn lookup_item_type(cx: ctxt, did: ast::def_id) -> ty_param_kinds_and_ty {
     }
 }
 
-fn ret_ty_of_fn_ty(cx: ctxt, a_ty: t) -> t {
-    alt ty::struct(cx, a_ty) {
-      ty::ty_fn(_, _, ret_ty, _, _) { ret ret_ty; }
-      ty::ty_native_fn(_, _, ret_ty) { ret ret_ty; }
-      _ {
-        cx.sess.bug("ret_ty_of_fn_ty() called on non-function type: " +
-                        ty_to_str(cx, a_ty));
-      }
-    }
-}
-
 fn ret_ty_of_fn(cx: ctxt, id: ast::node_id) -> t {
-    ret ret_ty_of_fn_ty(cx, node_id_to_type(cx, id));
+    ty_fn_ret(cx, node_id_to_type(cx, id))
 }
 
 fn is_binopable(cx: ctxt, ty: t, op: ast::binop) -> bool {