]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/middle/typeck/infer/unify.rs
rollup merge of #17355 : gamazeps/issue17210
[rust.git] / src / librustc / middle / typeck / infer / unify.rs
index adf0a25ce4002e5f8069c59e27afe1a4b679abaa..301582d55d6eb0bbfc6fca57126e468bbe6bf485 100644 (file)
@@ -258,6 +258,7 @@ fn reverse(&mut self, _: &mut Vec<VarValue<K,V>>, _: ()) {
  * relationship.
  */
 pub trait SimplyUnifiable : Clone + PartialEq + Repr {
+    fn to_type(&self) -> ty::t;
     fn to_type_err(expected_found<Self>) -> ty::type_err;
 }
 
@@ -286,10 +287,11 @@ fn simple_var_t(&self,
                     a_id: K,
                     b: V)
                     -> ures;
+    fn probe_var(&self, a_id: K) -> Option<ty::t>;
 }
 
-impl<'tcx,V:SimplyUnifiable,K:UnifyKey<Option<V>>>
-    InferCtxtMethodsForSimplyUnifiableTypes<V,K> for InferCtxt<'tcx>
+impl<'a,'tcx,V:SimplyUnifiable,K:UnifyKey<Option<V>>>
+    InferCtxtMethodsForSimplyUnifiableTypes<V,K> for InferCtxt<'a, 'tcx>
 {
     fn simple_vars(&self,
                    a_is_expected: bool,
@@ -370,6 +372,16 @@ fn simple_var_t(&self,
             }
         }
     }
+
+    fn probe_var(&self, a_id: K) -> Option<ty::t> {
+        let tcx = self.tcx;
+        let table = UnifyKey::unification_table(self);
+        let node_a = table.borrow_mut().get(tcx, a_id);
+        match node_a.value {
+            None => None,
+            Some(ref a_t) => Some(a_t.to_type())
+        }
+    }
 }
 
 ///////////////////////////////////////////////////////////////////////////
@@ -393,6 +405,13 @@ fn tag(_: Option<ty::IntVid>) -> &'static str {
 }
 
 impl SimplyUnifiable for IntVarValue {
+    fn to_type(&self) -> ty::t {
+        match *self {
+            ty::IntType(i) => ty::mk_mach_int(i),
+            ty::UintType(i) => ty::mk_mach_uint(i),
+        }
+    }
+
     fn to_type_err(err: expected_found<IntVarValue>) -> ty::type_err {
         return ty::terr_int_mismatch(err);
     }
@@ -422,6 +441,10 @@ impl UnifyValue for Option<ast::FloatTy> {
 }
 
 impl SimplyUnifiable for ast::FloatTy {
+    fn to_type(&self) -> ty::t {
+        ty::mk_mach_float(*self)
+    }
+
     fn to_type_err(err: expected_found<ast::FloatTy>) -> ty::type_err {
         return ty::terr_float_mismatch(err);
     }