]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/middle/subst.rs
Auto merge of #31077 - nagisa:mir-temp-promotion, r=dotdash
[rust.git] / src / librustc / middle / subst.rs
index d935b51813a5b0d9b99f4a79bc805863e2c64975..ddc817ffc023e0ee5c40c8436367334f6ff9cba9 100644 (file)
@@ -14,7 +14,8 @@
 pub use self::RegionSubsts::*;
 
 use middle::cstore;
-use middle::ty::{self, Ty, HasTypeFlags, RegionEscape};
+use middle::def_id::DefId;
+use middle::ty::{self, Ty};
 use middle::ty::fold::{TypeFoldable, TypeFolder};
 
 use serialize::{Encodable, Encoder, Decodable, Decoder};
@@ -142,16 +143,34 @@ pub fn with_method(self,
                        -> Substs<'tcx>
     {
         let Substs { types, regions } = self;
-        let types = types.with_vec(FnSpace, m_types);
-        let regions = regions.map(|r| r.with_vec(FnSpace, m_regions));
+        let types = types.with_slice(FnSpace, &m_types);
+        let regions = regions.map(|r| r.with_slice(FnSpace, &m_regions));
         Substs { types: types, regions: regions }
     }
 
-    pub fn method_to_trait(self) -> Substs<'tcx> {
-        let Substs { mut types, regions } = self;
+    pub fn with_method_from(self,
+                            meth_substs: &Substs<'tcx>)
+                            -> Substs<'tcx>
+    {
+        let Substs { types, regions } = self;
+        let types = types.with_slice(FnSpace, meth_substs.types.get_slice(FnSpace));
+        let regions = regions.map(|r| {
+            r.with_slice(FnSpace, meth_substs.regions().get_slice(FnSpace))
+        });
+        Substs { types: types, regions: regions }
+    }
+
+    /// Creates a trait-ref out of this substs, ignoring the FnSpace substs
+    pub fn to_trait_ref(&self, tcx: &ty::ctxt<'tcx>, trait_id: DefId)
+                        -> ty::TraitRef<'tcx> {
+        let Substs { mut types, regions } = self.clone();
         types.truncate(FnSpace, 0);
         let regions = regions.map(|mut r| { r.truncate(FnSpace, 0); r });
-        Substs { types: types, regions: regions }
+
+        ty::TraitRef {
+            def_id: trait_id,
+            substs: tcx.mk_substs(Substs { types: types, regions: regions })
+        }
     }
 }
 
@@ -290,10 +309,6 @@ pub fn empty() -> VecPerParamSpace<T> {
         }
     }
 
-    pub fn params_from_type(types: Vec<T>) -> VecPerParamSpace<T> {
-        VecPerParamSpace::empty().with_vec(TypeSpace, types)
-    }
-
     /// `t` is the type space.
     /// `s` is the self space.
     /// `f` is the fn space.
@@ -483,11 +498,15 @@ pub fn split(self) -> SeparateVecsPerParamSpace<T> {
         }
     }
 
-    pub fn with_vec(mut self, space: ParamSpace, vec: Vec<T>)
+    pub fn with_slice(mut self, space: ParamSpace, slice: &[T])
                     -> VecPerParamSpace<T>
+        where T: Clone
     {
         assert!(self.is_empty_in(space));
-        self.replace(space, vec);
+        for t in slice {
+            self.push(space, t.clone());
+        }
+
         self
     }
 }
@@ -674,7 +693,7 @@ fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
                 self.ty_for_param(p, t)
             }
             _ => {
-                t.fold_subitems_with(self)
+                t.super_fold_with(self)
             }
         };