]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/middle/typeck/variance.rs
rollup merge of #18407 : thestinger/arena
[rust.git] / src / librustc / middle / typeck / variance.rs
index 60a7aa77904420b151b397fa31f1d3823472ce03..b8c47cff48c6b1fe9f92dcbd667d0ae1114169d4 100644 (file)
@@ -232,6 +232,7 @@ pub fn infer_variance(tcx: &ty::ctxt) {
 
 type VarianceTermPtr<'a> = &'a VarianceTerm<'a>;
 
+#[deriving(Show)]
 struct InferredIndex(uint);
 
 enum VarianceTerm<'a> {
@@ -325,10 +326,10 @@ fn add_inferred(&mut self,
         assert!(newly_added);
 
         debug!("add_inferred(item_id={}, \
-                kind={:?}, \
+                kind={}, \
                 index={}, \
                 param_id={},
-                inf_index={:?})",
+                inf_index={})",
                 item_id, kind, index, param_id, inf_index);
     }
 
@@ -571,7 +572,7 @@ fn find_binding_for_lifetime(&self, param_id: ast::NodeId) -> ast::NodeId {
         match tcx.named_region_map.find(&param_id) {
             Some(&rl::DefEarlyBoundRegion(_, _, lifetime_decl_id))
                 => lifetime_decl_id,
-            Some(_) => fail!("should not encounter non early-bound cases"),
+            Some(_) => panic!("should not encounter non early-bound cases"),
 
             // The lookup should only fail when `param_id` is
             // itself a lifetime binding: use it as the decl_id.
@@ -596,11 +597,11 @@ fn is_to_be_inferred(&self, param_id: ast::NodeId) -> bool {
             assert!(is_lifetime(&tcx.map, param_id));
             let parent_id = tcx.map.get_parent(decl_id);
             let parent = tcx.map.find(parent_id).unwrap_or_else(
-                || fail!("tcx.map missing entry for id: {}", parent_id));
+                || panic!("tcx.map missing entry for id: {}", parent_id));
 
             let is_inferred;
             macro_rules! cannot_happen { () => { {
-                fail!("invalid parent: {:s} for {:s}",
+                panic!("invalid parent: {:s} for {:s}",
                       tcx.map.node_to_string(parent_id),
                       tcx.map.node_to_string(param_id));
             } } }
@@ -656,7 +657,7 @@ fn declared_variance(&self,
             // variance not yet inferred, so return a symbolic
             // variance.
             let InferredIndex(index) = self.inferred_index(param_def_id.node);
-            self.terms_cx.inferred_infos.get(index).term
+            self.terms_cx.inferred_infos[index].term
         } else {
             // Parameter on an item defined within another crate:
             // variance already inferred, just look it up.
@@ -714,7 +715,7 @@ fn xform(&mut self,
             }
 
             _ => {
-                self.terms_cx.arena.alloc(|| TransformTerm(v1, v2))
+                &*self.terms_cx.arena.alloc(|| TransformTerm(v1, v2))
             }
         }
     }
@@ -727,15 +728,14 @@ fn add_constraints_from_ty(&mut self,
         debug!("add_constraints_from_ty(ty={})", ty.repr(self.tcx()));
 
         match ty::get(ty).sty {
-            ty::ty_nil | ty::ty_bot | ty::ty_bool |
+            ty::ty_nil | ty::ty_bool |
             ty::ty_char | ty::ty_int(_) | ty::ty_uint(_) |
             ty::ty_float(_) | ty::ty_str => {
                 /* leaf type -- noop */
             }
 
-            ty::ty_unboxed_closure(_, region) => {
-                let contra = self.contravariant(variance);
-                self.add_constraints_from_region(region, contra);
+            ty::ty_unboxed_closure(..) => {
+                self.tcx().sess.bug("Unexpected unboxed closure type in variance computation");
             }
 
             ty::ty_rptr(region, ref mt) => {
@@ -804,7 +804,7 @@ fn add_constraints_from_ty(&mut self,
                     variance);
             }
 
-            ty::ty_param(ty::ParamTy { def_id: ref def_id, .. }) => {
+            ty::ty_param(ty::ParamTy { ref def_id, .. }) => {
                 assert_eq!(def_id.krate, ast::LOCAL_CRATE);
                 match self.terms_cx.inferred_map.find(&def_id.node) {
                     Some(&index) => {
@@ -852,7 +852,7 @@ fn add_constraints_from_substs(&mut self,
                                    region_param_defs: &[ty::RegionParameterDef],
                                    substs: &subst::Substs,
                                    variance: VarianceTermPtr<'a>) {
-        debug!("add_constraints_from_substs(def_id={:?})", def_id);
+        debug!("add_constraints_from_substs(def_id={})", def_id);
 
         for p in type_param_defs.iter() {
             let variance_decl =
@@ -882,7 +882,9 @@ fn add_constraints_from_sig(&mut self,
         for &input in sig.inputs.iter() {
             self.add_constraints_from_ty(input, contra);
         }
-        self.add_constraints_from_ty(sig.output, variance);
+        if let ty::FnConverging(result_type) = sig.output {
+            self.add_constraints_from_ty(result_type, variance);
+        }
     }
 
     /// Adds constraints appropriate for a region appearing in a
@@ -979,15 +981,14 @@ fn solve(&mut self) {
                 let Constraint { inferred, variance: term } = *constraint;
                 let InferredIndex(inferred) = inferred;
                 let variance = self.evaluate(term);
-                let old_value = *self.solutions.get(inferred);
+                let old_value = self.solutions[inferred];
                 let new_value = glb(variance, old_value);
                 if old_value != new_value {
                     debug!("Updating inferred {} (node {}) \
                             from {} to {} due to {}",
                             inferred,
                             self.terms_cx
-                                .inferred_infos
-                                .get(inferred)
+                                .inferred_infos[inferred]
                                 .param_id,
                             old_value,
                             new_value,
@@ -1016,14 +1017,14 @@ fn write(&self) {
         let mut index = 0;
         let num_inferred = self.terms_cx.num_inferred();
         while index < num_inferred {
-            let item_id = inferred_infos.get(index).item_id;
+            let item_id = inferred_infos[index].item_id;
             let mut types = VecPerParamSpace::empty();
             let mut regions = VecPerParamSpace::empty();
 
             while index < num_inferred &&
-                  inferred_infos.get(index).item_id == item_id {
-                let info = inferred_infos.get(index);
-                let variance = *solutions.get(index);
+                  inferred_infos[index].item_id == item_id {
+                let info = inferred_infos[index];
+                let variance = solutions[index];
                 debug!("Index {} Info {} / {} / {} Variance {}",
                        index, info.index, info.kind, info.space, variance);
                 match info.kind {
@@ -1073,7 +1074,7 @@ fn evaluate(&self, term: VarianceTermPtr<'a>) -> ty::Variance {
             }
 
             InferredTerm(InferredIndex(index)) => {
-                *self.solutions.get(index)
+                self.solutions[index]
             }
         }
     }