about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2011-05-13 16:40:21 -0700
committerPatrick Walton <pcwalton@mimiga.net>2011-05-13 16:40:21 -0700
commit0739849e9fe9013d87ec6bc7f026143a10079703 (patch)
tree41bcfb59b24ea1bd573bb24e57859f1234398137
parent4f2eb3187098888304444f41ada25ce120662651 (diff)
downloadrust-0739849e9fe9013d87ec6bc7f026143a10079703.tar.gz
rust-0739849e9fe9013d87ec6bc7f026143a10079703.zip
rustc: Make all type lookups go through the one ty::ann_to_ty_param_substs_opt_and_ty() function
-rw-r--r--src/comp/middle/ty.rs66
1 files changed, 22 insertions, 44 deletions
diff --git a/src/comp/middle/ty.rs b/src/comp/middle/ty.rs
index 5957c1fdf36..fcee03bf0e4 100644
--- a/src/comp/middle/ty.rs
+++ b/src/comp/middle/ty.rs
@@ -1440,35 +1440,7 @@ fn eq_raw_ty(&raw_t a, &raw_t b) -> bool {
 fn eq_ty(&t a, &t b) -> bool { ret a == b; }
 
 
-fn ann_to_type(&node_type_table ntt, &ast::ann ann) -> t {
-    alt (ann) {
-        case (ast::ann_none(_)) {
-            log_err "ann_to_type() called on node with no type";
-            fail;
-        }
-        case (ast::ann_type(_, ?ty, _, _)) {
-            ret ty;
-        }
-    }
-}
-
-fn ann_to_type_params(&node_type_table ntt, &ast::ann ann) -> vec[t] {
-    alt (ann) {
-        case (ast::ann_none(_)) {
-            log_err "ann_to_type_params() called on node with no type params";
-            fail;
-        }
-        case (ast::ann_type(_, _, ?tps, _)) {
-            alt (tps) {
-                case (none[vec[t]]) {
-                    let vec[t] result = vec();
-                    ret result;
-                }
-                case (some[vec[t]](?tps)) { ret tps; }
-            }
-        }
-    }
-}
+// Type lookups
 
 fn ann_to_ty_param_substs_opt_and_ty(&node_type_table ntt, &ast::ann ann)
         -> ty_param_substs_opt_and_ty {
@@ -1482,27 +1454,33 @@ fn ann_to_ty_param_substs_opt_and_ty(&node_type_table ntt, &ast::ann ann)
     }
 }
 
+fn ann_to_type(&node_type_table ntt, &ast::ann ann) -> t {
+    ret ann_to_ty_param_substs_opt_and_ty(ntt, ann)._1;
+}
+
+fn ann_to_type_params(&node_type_table ntt, &ast::ann ann) -> vec[t] {
+    alt (ann_to_ty_param_substs_opt_and_ty(ntt, ann)._0) {
+        case (none[vec[t]]) {
+            let vec[t] result = vec();
+            ret result;
+        }
+        case (some[vec[t]](?tps)) { ret tps; }
+    }
+}
+
 // Returns the type of an annotation, with type parameter substitutions
 // performed if applicable.
-fn ann_to_monotype(ctxt cx,  &node_type_table ntt, ast::ann a) -> t {
-    // TODO: Refactor to use recursive pattern matching when we're more
-    // confident that it works.
-    alt (a) {
-        case (ast::ann_none(_)) {
-            log_err "ann_to_monotype() called on expression with no type!";
-            fail;
-        }
-        case (ast::ann_type(_, ?typ, ?tps_opt, _)) {
-            alt (tps_opt) {
-                case (none[vec[t]]) { ret typ; }
-                case (some[vec[t]](?tps)) {
-                    ret substitute_type_params(cx, tps, typ);
-                }
-            }
+fn ann_to_monotype(ctxt cx, &node_type_table ntt, ast::ann a) -> t {
+    auto tpot = ann_to_ty_param_substs_opt_and_ty(ntt, a);
+    alt (tpot._0) {
+        case (none[vec[t]]) { ret tpot._1; }
+        case (some[vec[t]](?tps)) {
+            ret substitute_type_params(cx, tps, tpot._1);
         }
     }
 }
 
+
 // Turns a type into an ann_type, using defaults for other fields.
 fn triv_ann(uint node_id, t typ) -> ast::ann {
     ret ast::ann_type(node_id, typ, none[vec[t]], none[@ts_ann]);