]> git.lizzy.rs Git - rust.git/commitdiff
rustc: don't expose Substs::fill_item as public.
authorEduard-Mihai Burtescu <edy.burt@gmail.com>
Wed, 16 May 2018 08:56:50 +0000 (11:56 +0300)
committerEduard-Mihai Burtescu <edy.burt@gmail.com>
Mon, 21 May 2018 09:13:19 +0000 (12:13 +0300)
src/librustc/ty/subst.rs
src/librustc_typeck/astconv.rs

index c9c31372d560097634c1cc7dc9bad946a7c693f2..57401ac19f3c565bf614877e783b8cb09f14481c 100644 (file)
@@ -195,10 +195,10 @@ pub fn extend_to<F>(&self,
         tcx.intern_substs(&result)
     }
 
-    pub fn fill_item<F>(substs: &mut Vec<Kind<'tcx>>,
-                             tcx: TyCtxt<'a, 'gcx, 'tcx>,
-                             defs: &ty::Generics,
-                             mk_kind: &mut F)
+    fn fill_item<F>(substs: &mut Vec<Kind<'tcx>>,
+                    tcx: TyCtxt<'a, 'gcx, 'tcx>,
+                    defs: &ty::Generics,
+                    mk_kind: &mut F)
     where F: FnMut(&ty::GenericParamDef, &[Kind<'tcx>]) -> Kind<'tcx>
     {
 
@@ -210,8 +210,8 @@ pub fn fill_item<F>(substs: &mut Vec<Kind<'tcx>>,
     }
 
     fn fill_single<F>(substs: &mut Vec<Kind<'tcx>>,
-                           defs: &ty::Generics,
-                           mk_kind: &mut F)
+                      defs: &ty::Generics,
+                      mk_kind: &mut F)
     where F: FnMut(&ty::GenericParamDef, &[Kind<'tcx>]) -> Kind<'tcx>
     {
         for param in &defs.params {
index 2af3a7ae4c6250104b19cc47b2985f37ecbe286e..c89fe8ff5b67ab86da4101d8e07d0b7801cd591a 100644 (file)
@@ -18,7 +18,7 @@
 use hir::def_id::DefId;
 use middle::resolve_lifetime as rl;
 use namespace::Namespace;
-use rustc::ty::subst::{UnpackedKind, Subst, Substs};
+use rustc::ty::subst::{Subst, Substs};
 use rustc::traits;
 use rustc::ty::{self, Ty, TyCtxt, ToPredicate, TypeFoldable};
 use rustc::ty::GenericParamDefKind;
@@ -1152,32 +1152,29 @@ pub fn impl_trait_ty_to_ty(&self, def_id: DefId, lifetimes: &[hir::Lifetime]) ->
         let tcx = self.tcx();
         let generics = tcx.generics_of(def_id);
 
-        // Fill in the substs of the parent generics
         debug!("impl_trait_ty_to_ty: generics={:?}", generics);
-        let mut substs = Vec::with_capacity(generics.count());
-        if let Some(parent_id) = generics.parent {
-            let parent_generics = tcx.generics_of(parent_id);
-            Substs::fill_item(&mut substs, tcx, parent_generics, &mut |param, _| {
-                tcx.mk_param_from_def(param)
-            });
-
-            // Replace all lifetimes with 'static
-            for subst in &mut substs {
-                if let UnpackedKind::Lifetime(_) = subst.unpack() {
-                    *subst = tcx.types.re_static.into();
+        let substs = Substs::for_item(tcx, def_id, |param, _| {
+            if let Some(i) = (param.index as usize).checked_sub(generics.parent_count) {
+                // Our own parameters are the resolved lifetimes.
+                match param.kind {
+                    GenericParamDefKind::Lifetime => {
+                        self.ast_region_to_region(&lifetimes[i], None).into()
+                    }
+                    _ => bug!()
+                }
+            } else {
+                // Replace all parent lifetimes with 'static.
+                match param.kind {
+                    GenericParamDefKind::Lifetime => {
+                        tcx.types.re_static.into()
+                    }
+                    _ => tcx.mk_param_from_def(param)
                 }
             }
-            debug!("impl_trait_ty_to_ty: substs from parent = {:?}", substs);
-        }
-        assert_eq!(substs.len(), generics.parent_count);
-
-        // Fill in our own generics with the resolved lifetimes
-        assert_eq!(lifetimes.len(), generics.params.len());
-        substs.extend(lifetimes.iter().map(|lt| self.ast_region_to_region(lt, None).into()));
-
+        });
         debug!("impl_trait_ty_to_ty: final substs = {:?}", substs);
 
-        tcx.mk_anon(def_id, tcx.intern_substs(&substs))
+        tcx.mk_anon(def_id, substs)
     }
 
     pub fn ty_of_arg(&self,