]> git.lizzy.rs Git - rust.git/commitdiff
remove ErasedRegions from substitutions
authorNiko Matsakis <niko@alum.mit.edu>
Wed, 9 Mar 2016 23:22:05 +0000 (18:22 -0500)
committerNiko Matsakis <niko@alum.mit.edu>
Thu, 24 Mar 2016 18:01:28 +0000 (14:01 -0400)
This hack has long since outlived its usefulness; the transition to
trans passing around full substitutions is basically done. Instead of
`ErasedRegions`, just supply substitutions with a suitable number of
`'static` entries, and invoke `erase_regions` when needed (the latter of
which we already do).

32 files changed:
src/librustc/middle/subst.rs
src/librustc/middle/traits/specialize/mod.rs
src/librustc/middle/ty/flags.rs
src/librustc/middle/ty/fold.rs
src/librustc/middle/ty/mod.rs
src/librustc/middle/ty/relate.rs
src/librustc/middle/ty/structural_impls.rs
src/librustc/middle/ty/sty.rs
src/librustc/util/ppaux.rs
src/librustc_metadata/tydecode.rs
src/librustc_metadata/tyencode.rs
src/librustc_trans/trans/base.rs
src/librustc_trans/trans/callee.rs
src/librustc_trans/trans/closure.rs
src/librustc_trans/trans/collector.rs
src/librustc_trans/trans/consts.rs
src/librustc_trans/trans/context.rs
src/librustc_trans/trans/expr.rs
src/librustc_trans/trans/glue.rs
src/librustc_trans/trans/inline.rs
src/librustc_trans/trans/intrinsic.rs
src/librustc_trans/trans/meth.rs
src/librustc_trans/trans/monomorphize.rs
src/librustc_typeck/astconv.rs
src/librustc_typeck/check/compare_method.rs
src/librustc_typeck/check/method/confirm.rs
src/librustc_typeck/check/method/probe.rs
src/librustc_typeck/check/mod.rs
src/librustc_typeck/check/regionck.rs
src/librustc_typeck/constrained_type_params.rs
src/librustc_typeck/variance/constraints.rs
src/librustdoc/clean/mod.rs

index 510a3dd454b95fcf3307ae9d0d065c9f2fc0b6b9..b9bf550704e02e8f0e440f2557fb16078c9d3a9f 100644 (file)
@@ -11,7 +11,6 @@
 // Type substitutions.
 
 pub use self::ParamSpace::*;
-pub use self::RegionSubsts::*;
 
 use middle::cstore;
 use middle::def_id::DefId;
 #[derive(Clone, PartialEq, Eq, Hash)]
 pub struct Substs<'tcx> {
     pub types: VecPerParamSpace<Ty<'tcx>>,
-    pub regions: RegionSubsts,
-}
-
-/// Represents the values to use when substituting lifetime parameters.
-/// If the value is `ErasedRegions`, then this subst is occurring during
-/// trans, and all region parameters will be replaced with `ty::ReStatic`.
-#[derive(Clone, PartialEq, Eq, Hash)]
-pub enum RegionSubsts {
-    ErasedRegions,
-    NonerasedRegions(VecPerParamSpace<ty::Region>)
+    pub regions: VecPerParamSpace<ty::Region>,
 }
 
 impl<'tcx> Substs<'tcx> {
@@ -51,7 +41,7 @@ pub fn new(t: VecPerParamSpace<Ty<'tcx>>,
                r: VecPerParamSpace<ty::Region>)
                -> Substs<'tcx>
     {
-        Substs { types: t, regions: NonerasedRegions(r) }
+        Substs { types: t, regions: r }
     }
 
     pub fn new_type(t: Vec<Ty<'tcx>>,
@@ -71,32 +61,15 @@ pub fn new_trait(t: Vec<Ty<'tcx>>,
                     VecPerParamSpace::new(r, Vec::new(), Vec::new()))
     }
 
-    pub fn erased(t: VecPerParamSpace<Ty<'tcx>>) -> Substs<'tcx>
-    {
-        Substs { types: t, regions: ErasedRegions }
-    }
-
     pub fn empty() -> Substs<'tcx> {
         Substs {
             types: VecPerParamSpace::empty(),
-            regions: NonerasedRegions(VecPerParamSpace::empty()),
-        }
-    }
-
-    pub fn trans_empty() -> Substs<'tcx> {
-        Substs {
-            types: VecPerParamSpace::empty(),
-            regions: ErasedRegions
+            regions: VecPerParamSpace::empty(),
         }
     }
 
     pub fn is_noop(&self) -> bool {
-        let regions_is_noop = match self.regions {
-            ErasedRegions => false, // may be used to canonicalize
-            NonerasedRegions(ref regions) => regions.is_empty(),
-        };
-
-        regions_is_noop && self.types.is_empty()
+        self.regions.is_empty() && self.types.is_empty()
     }
 
     pub fn type_for_def(&self, ty_param_def: &ty::TypeParameterDef) -> Ty<'tcx> {
@@ -115,26 +88,9 @@ pub fn with_self_ty(&self, self_ty: Ty<'tcx>) -> Substs<'tcx> {
     }
 
     pub fn erase_regions(self) -> Substs<'tcx> {
-        let Substs { types, regions: _ } = self;
-        Substs { types: types, regions: ErasedRegions }
-    }
-
-    /// Since ErasedRegions are only to be used in trans, most of the compiler can use this method
-    /// to easily access the set of region substitutions.
-    pub fn regions<'a>(&'a self) -> &'a VecPerParamSpace<ty::Region> {
-        match self.regions {
-            ErasedRegions => panic!("Erased regions only expected in trans"),
-            NonerasedRegions(ref r) => r
-        }
-    }
-
-    /// Since ErasedRegions are only to be used in trans, most of the compiler can use this method
-    /// to easily access the set of region substitutions.
-    pub fn mut_regions<'a>(&'a mut self) -> &'a mut VecPerParamSpace<ty::Region> {
-        match self.regions {
-            ErasedRegions => panic!("Erased regions only expected in trans"),
-            NonerasedRegions(ref mut r) => r
-        }
+        let Substs { types, regions } = self;
+        let regions = regions.map(|_| ty::ReStatic);
+        Substs { types: types, regions: regions }
     }
 
     pub fn with_method(self,
@@ -144,7 +100,7 @@ pub fn with_method(self,
     {
         let Substs { types, regions } = self;
         let types = types.with_slice(FnSpace, &m_types);
-        let regions = regions.map(|r| r.with_slice(FnSpace, &m_regions));
+        let regions = regions.with_slice(FnSpace, &m_regions);
         Substs { types: types, regions: regions }
     }
 
@@ -154,27 +110,23 @@ pub fn with_method_from(&self,
     {
         let Substs { types, regions } = self.clone();
         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))
-        });
+        let regions = regions.with_slice(FnSpace, meth_substs.regions.get_slice(FnSpace));
         Substs { types: types, regions: regions }
     }
 
     pub fn with_method_from_subst(self, other: &Substs<'tcx>) -> Substs<'tcx> {
         let Substs { types, regions } = self;
         let types = types.with_slice(FnSpace, other.types.get_slice(FnSpace));
-        let regions = regions.map(|r| {
-            r.with_slice(FnSpace, other.regions().get_slice(FnSpace))
-        });
+        let regions = regions.with_slice(FnSpace, other.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: &TyCtxt<'tcx>, trait_id: DefId)
                         -> ty::TraitRef<'tcx> {
-        let Substs { mut types, regions } = self.clone();
+        let Substs { mut types, mut regions } = self.clone();
         types.truncate(FnSpace, 0);
-        let regions = regions.map(|mut r| { r.truncate(FnSpace, 0); r });
+        regions.truncate(FnSpace, 0);
 
         ty::TraitRef {
             def_id: trait_id,
@@ -212,24 +164,6 @@ fn decode<D: Decoder>(d: &mut D) -> Result<&'tcx Substs<'tcx>, D::Error> {
     }
 }
 
-impl RegionSubsts {
-    pub fn map<F>(self, op: F) -> RegionSubsts where
-        F: FnOnce(VecPerParamSpace<ty::Region>) -> VecPerParamSpace<ty::Region>,
-    {
-        match self {
-            ErasedRegions => ErasedRegions,
-            NonerasedRegions(r) => NonerasedRegions(op(r))
-        }
-    }
-
-    pub fn is_erased(&self) -> bool {
-        match *self {
-            ErasedRegions => true,
-            NonerasedRegions(_) => false,
-        }
-    }
-}
-
 ///////////////////////////////////////////////////////////////////////////
 // ParamSpace
 
@@ -664,26 +598,22 @@ fn fold_region(&mut self, r: ty::Region) -> ty::Region {
         // the specialized routine `ty::replace_late_regions()`.
         match r {
             ty::ReEarlyBound(data) => {
-                match self.substs.regions {
-                    ErasedRegions => ty::ReStatic,
-                    NonerasedRegions(ref regions) =>
-                        match regions.opt_get(data.space, data.index as usize) {
-                            Some(&r) => {
-                                self.shift_region_through_binders(r)
-                            }
-                            None => {
-                                let span = self.span.unwrap_or(DUMMY_SP);
-                                self.tcx().sess.span_bug(
-                                    span,
-                                    &format!("Type parameter out of range \
-                                              when substituting in region {} (root type={:?}) \
-                                              (space={:?}, index={})",
-                                             data.name,
-                                             self.root_ty,
-                                             data.space,
-                                             data.index));
-                            }
-                        }
+                match self.substs.regions.opt_get(data.space, data.index as usize) {
+                    Some(&r) => {
+                        self.shift_region_through_binders(r)
+                    }
+                    None => {
+                        let span = self.span.unwrap_or(DUMMY_SP);
+                        self.tcx().sess.span_bug(
+                            span,
+                            &format!("Region parameter out of range \
+                                      when substituting in region {} (root type={:?}) \
+                                      (space={:?}, index={})",
+                                     data.name,
+                                     self.root_ty,
+                                     data.space,
+                                     data.index));
+                    }
                 }
             }
             _ => r
index a692fe55a77899e79d5b27a19b8b17280d39cbc0..92478f2874e1e9add0ae4b5909e7f014a80c3046 100644 (file)
@@ -102,14 +102,6 @@ pub fn translate_substs<'a, 'tcx>(infcx: &InferCtxt<'a, 'tcx>,
         specialization_graph::Node::Trait(..) => source_trait_ref.substs.clone(),
     };
 
-    // retain erasure mode
-    // NB: this must happen before inheriting method generics below
-    let target_substs = if source_substs.regions.is_erased() {
-        target_substs.erase_regions()
-    } else {
-        target_substs
-    };
-
     // directly inherent the method generics, since those do not vary across impls
     infcx.tcx.mk_substs(target_substs.with_method_from_subst(source_substs))
 }
index c491bd6ca5e99d6dad0d4812ef34b0c042aa5708..c874e9b7ca52d67d32f65ff145ed0982dd366f92 100644 (file)
@@ -194,13 +194,8 @@ fn add_projection_ty(&mut self, projection_ty: &ty::ProjectionTy) {
 
     fn add_substs(&mut self, substs: &subst::Substs) {
         self.add_tys(substs.types.as_slice());
-        match substs.regions {
-            subst::ErasedRegions => {}
-            subst::NonerasedRegions(ref regions) => {
-                for &r in regions {
-                    self.add_region(r);
-                }
-            }
+        for &r in &substs.regions {
+            self.add_region(r);
         }
     }
 
index 090d4eeb87437bcc7bf7cb783fd7c0d9881657ff..f754e5c5a0a7d5008596c0f067594d624dc253a6 100644 (file)
@@ -532,7 +532,7 @@ fn fold_region(&mut self, r: ty::Region) -> ty::Region {
             fn fold_substs(&mut self,
                            substs: &subst::Substs<'tcx>)
                            -> subst::Substs<'tcx> {
-                subst::Substs { regions: subst::ErasedRegions,
+                subst::Substs { regions: substs.regions.fold_with(self),
                                 types: substs.types.fold_with(self) }
             }
         }
index 6a081cb8dd10264ab2ba3dedc7de6e0e348506d5..050024d0e94ea4c20fd7601642390bc57eee883b 100644 (file)
@@ -2605,7 +2605,7 @@ pub fn construct_free_substs(&self, generics: &Generics<'tcx>,
 
         Substs {
             types: types,
-            regions: subst::NonerasedRegions(regions)
+            regions: regions,
         }
     }
 
index 1df7a440f4f16d5ba88e6072f1e54dd7cd1c1404..563ff346a6440d169f21f5e9221470a46a185182 100644 (file)
@@ -14,7 +14,7 @@
 //! type equality, etc.
 
 use middle::def_id::DefId;
-use middle::subst::{ErasedRegions, NonerasedRegions, ParamSpace, Substs};
+use middle::subst::{ParamSpace, Substs};
 use middle::ty::{self, Ty, TyCtxt, TypeFoldable};
 use middle::ty::error::{ExpectedFound, TypeError};
 use std::rc::Rc;
@@ -156,23 +156,15 @@ pub fn relate_substs<'a,'tcx:'a,R>(relation: &mut R,
         substs.types.replace(space, tps);
     }
 
-    match (&a_subst.regions, &b_subst.regions) {
-        (&ErasedRegions, _) | (_, &ErasedRegions) => {
-            substs.regions = ErasedRegions;
-        }
-
-        (&NonerasedRegions(ref a), &NonerasedRegions(ref b)) => {
-            for &space in &ParamSpace::all() {
-                let a_regions = a.get_slice(space);
-                let b_regions = b.get_slice(space);
-                let r_variances = variances.map(|v| v.regions.get_slice(space));
-                let regions = relate_region_params(relation,
-                                                   r_variances,
-                                                   a_regions,
-                                                   b_regions)?;
-                substs.mut_regions().replace(space, regions);
-            }
-        }
+    for &space in &ParamSpace::all() {
+        let a_regions = a_subst.regions.get_slice(space);
+        let b_regions = b_subst.regions.get_slice(space);
+        let r_variances = variances.map(|v| v.regions.get_slice(space));
+        let regions = relate_region_params(relation,
+                                           r_variances,
+                                           a_regions,
+                                           b_regions)?;
+        substs.regions.replace(space, regions);
     }
 
     Ok(substs)
index 57cfdd0d8b8aecd727a8fa58d9ea36e811dd098d..0358fa2f1245593c860672c1f75b1ac29e7bad85 100644 (file)
@@ -487,14 +487,7 @@ fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
 
 impl<'tcx> TypeFoldable<'tcx> for subst::Substs<'tcx> {
     fn super_fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
-        let regions = match self.regions {
-            subst::ErasedRegions => subst::ErasedRegions,
-            subst::NonerasedRegions(ref regions) => {
-                subst::NonerasedRegions(regions.fold_with(folder))
-            }
-        };
-
-        subst::Substs { regions: regions,
+        subst::Substs { regions: self.regions.fold_with(folder),
                         types: self.types.fold_with(folder) }
     }
 
@@ -503,10 +496,7 @@ fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> Self {
     }
 
     fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> bool {
-        self.types.visit_with(visitor) || match self.regions {
-            subst::ErasedRegions => false,
-            subst::NonerasedRegions(ref regions) => regions.visit_with(visitor),
-        }
+        self.types.visit_with(visitor) || self.regions.visit_with(visitor)
     }
 }
 
index 6b1ccf3b1624a8fd5252911fdd9aaf2bef01a3bd..7a17b24df5e9d9feea1cd367bb512f48bc062539 100644 (file)
@@ -1204,18 +1204,18 @@ pub fn regions(&self) -> Vec<ty::Region> {
             TyTrait(ref obj) => {
                 let mut v = vec![obj.bounds.region_bound];
                 v.extend_from_slice(obj.principal.skip_binder()
-                                       .substs.regions().as_slice());
+                                       .substs.regions.as_slice());
                 v
             }
             TyEnum(_, substs) |
             TyStruct(_, substs) => {
-                substs.regions().as_slice().to_vec()
+                substs.regions.as_slice().to_vec()
             }
             TyClosure(_, ref substs) => {
-                substs.func_substs.regions().as_slice().to_vec()
+                substs.func_substs.regions.as_slice().to_vec()
             }
             TyProjection(ref data) => {
-                data.trait_ref.substs.regions().as_slice().to_vec()
+                data.trait_ref.substs.regions.as_slice().to_vec()
             }
             TyFnDef(..) |
             TyFnPtr(_) |
index 64619e40f49414c34092a11edf4e6ee66f4a8b98..6e7f49516e8faffc7c107e140d810d66ee1ae2fa 100644 (file)
@@ -104,17 +104,9 @@ pub fn parameterized<GG>(f: &mut fmt::Formatter,
     };
 
     if verbose {
-        match substs.regions {
-            subst::ErasedRegions => {
-                start_or_continue(f, "<", ", ")?;
-                write!(f, "..")?;
-            }
-            subst::NonerasedRegions(ref regions) => {
-                for region in regions {
-                    start_or_continue(f, "<", ", ")?;
-                    write!(f, "{:?}", region)?;
-                }
-            }
+        for region in &substs.regions {
+            start_or_continue(f, "<", ", ")?;
+            write!(f, "{:?}", region)?;
         }
         for &ty in &substs.types {
             start_or_continue(f, "<", ", ")?;
@@ -136,23 +128,18 @@ pub fn parameterized<GG>(f: &mut fmt::Formatter,
         }
     }
 
-    match substs.regions {
-        subst::ErasedRegions => { }
-        subst::NonerasedRegions(ref regions) => {
-            for &r in regions {
-                start_or_continue(f, "<", ", ")?;
-                let s = r.to_string();
-                if s.is_empty() {
-                    // This happens when the value of the region
-                    // parameter is not easily serialized. This may be
-                    // because the user omitted it in the first place,
-                    // or because it refers to some block in the code,
-                    // etc. I'm not sure how best to serialize this.
-                    write!(f, "'_")?;
-                } else {
-                    write!(f, "{}", s)?;
-                }
-            }
+    for &r in &substs.regions {
+        start_or_continue(f, "<", ", ")?;
+        let s = r.to_string();
+        if s.is_empty() {
+            // This happens when the value of the region
+            // parameter is not easily serialized. This may be
+            // because the user omitted it in the first place,
+            // or because it refers to some block in the code,
+            // etc. I'm not sure how best to serialize this.
+            write!(f, "'_")?;
+        } else {
+            write!(f, "{}", s)?;
         }
     }
 
@@ -393,15 +380,6 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
     }
 }
 
-impl fmt::Debug for subst::RegionSubsts {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        match *self {
-            subst::ErasedRegions => write!(f, "erased"),
-            subst::NonerasedRegions(ref regions) => write!(f, "{:?}", regions)
-        }
-    }
-}
-
 impl<'tcx> fmt::Debug for ty::TraitRef<'tcx> {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         // when printing out the debug representation, we don't need
index e9b23eb0458560e0ca378a33b47558b7fd6a4f4a..cd9c2e828bdefa6c1325bb79c4062fcdef2f8b27 100644 (file)
@@ -144,22 +144,11 @@ fn parse_vec_per_param_space<T, F>(&mut self, mut f: F) -> VecPerParamSpace<T> w
     }
 
     pub fn parse_substs(&mut self) -> subst::Substs<'tcx> {
-        let regions = self.parse_region_substs();
+        let regions = self.parse_vec_per_param_space(|this| this.parse_region());
         let types = self.parse_vec_per_param_space(|this| this.parse_ty());
         subst::Substs { types: types, regions: regions }
     }
 
-    fn parse_region_substs(&mut self) -> subst::RegionSubsts {
-        match self.next() {
-            'e' => subst::ErasedRegions,
-            'n' => {
-                subst::NonerasedRegions(
-                    self.parse_vec_per_param_space(|this| this.parse_region()))
-            }
-            _ => panic!("parse_bound_region: bad input")
-        }
-    }
-
     fn parse_bound_region(&mut self) -> ty::BoundRegion {
         match self.next() {
             'a' => {
index a6601e591ab67ecc720097fa4db103a7ade8989c..4718732c8a037ca9f5448bb516d38e939885ba47 100644 (file)
@@ -246,24 +246,12 @@ fn enc_vec_per_param_space<'a, 'tcx, T, F>(w: &mut Cursor<Vec<u8>>,
 
 pub fn enc_substs<'a, 'tcx>(w: &mut Cursor<Vec<u8>>, cx: &ctxt<'a, 'tcx>,
                             substs: &subst::Substs<'tcx>) {
-    enc_region_substs(w, cx, &substs.regions);
+    enc_vec_per_param_space(w, cx, &substs.regions,
+                            |w, cx, &r| enc_region(w, cx, r));
     enc_vec_per_param_space(w, cx, &substs.types,
                             |w, cx, &ty| enc_ty(w, cx, ty));
 }
 
-fn enc_region_substs(w: &mut Cursor<Vec<u8>>, cx: &ctxt, substs: &subst::RegionSubsts) {
-    match *substs {
-        subst::ErasedRegions => {
-            write!(w, "e");
-        }
-        subst::NonerasedRegions(ref regions) => {
-            write!(w, "n");
-            enc_vec_per_param_space(w, cx, regions,
-                                    |w, cx, &r| enc_region(w, cx, r));
-        }
-    }
-}
-
 pub fn enc_region(w: &mut Cursor<Vec<u8>>, cx: &ctxt, r: ty::Region) {
     match r {
         ty::ReLateBound(id, br) => {
index 1844c41760c5f5dbd3561dd7c943cbb479dcbfc2..d72028150a8a6679b14f23297a61a7350dd8d148 100644 (file)
@@ -673,9 +673,11 @@ pub fn custom_coerce_unsize_info<'ccx, 'tcx>(ccx: &CrateContext<'ccx, 'tcx>,
                                              source_ty: Ty<'tcx>,
                                              target_ty: Ty<'tcx>)
                                              -> CustomCoerceUnsized {
-    let trait_substs = Substs::erased(subst::VecPerParamSpace::new(vec![target_ty],
-                                                                   vec![source_ty],
-                                                                   Vec::new()));
+    let trait_substs = Substs::new(subst::VecPerParamSpace::new(vec![target_ty],
+                                                                vec![source_ty],
+                                                                Vec::new()),
+                                   subst::VecPerParamSpace::empty());
+
     let trait_ref = ty::Binder(ty::TraitRef {
         def_id: ccx.tcx().lang_items.coerce_unsized_trait().unwrap(),
         substs: ccx.tcx().mk_substs(trait_substs)
@@ -1824,10 +1826,8 @@ pub fn trans_closure<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
     ccx.stats().n_closures.set(ccx.stats().n_closures.get() + 1);
 
     if collector::collecting_debug_information(ccx) {
-        ccx.record_translation_item_as_generated(TransItem::Fn(Instance {
-            def: def_id,
-            params: &param_substs.types
-        }))
+        ccx.record_translation_item_as_generated(
+            TransItem::Fn(Instance::new(def_id, param_substs)));
     }
 
     let _icx = push_ctxt("trans_closure");
@@ -2259,7 +2259,7 @@ pub fn trans_item(ccx: &CrateContext, item: &hir::Item) {
                 // compilation unit that references the item, so it will still get
                 // translated everywhere it's needed.
                 for (ref ccx, is_origin) in ccx.maybe_iter(!from_external && trans_everywhere) {
-                    let empty_substs = tcx.mk_substs(Substs::trans_empty());
+                    let empty_substs = ccx.empty_substs_for_node_id(item.id);
                     let def_id = tcx.map.local_def_id(item.id);
                     let llfn = Callee::def(ccx, def_id, empty_substs).reify(ccx).val;
                     trans_fn(ccx, &decl, &body, llfn, empty_substs, item.id);
@@ -2298,7 +2298,7 @@ pub fn trans_item(ccx: &CrateContext, item: &hir::Item) {
                     if sig.generics.ty_params.is_empty() {
                         let trans_everywhere = attr::requests_inline(&impl_item.attrs);
                         for (ref ccx, is_origin) in ccx.maybe_iter(trans_everywhere) {
-                            let empty_substs = tcx.mk_substs(Substs::trans_empty());
+                            let empty_substs = ccx.empty_substs_for_node_id(impl_item.id);
                             let def_id = tcx.map.local_def_id(impl_item.id);
                             let llfn = Callee::def(ccx, def_id, empty_substs).reify(ccx).val;
                             trans_fn(ccx, &sig.decl, body, llfn, empty_substs, impl_item.id);
@@ -2389,7 +2389,7 @@ fn create_entry_fn(ccx: &CrateContext,
                     Ok(id) => id,
                     Err(s) => ccx.sess().fatal(&s)
                 };
-                let empty_substs = ccx.tcx().mk_substs(Substs::trans_empty());
+                let empty_substs = ccx.tcx().mk_substs(Substs::empty());
                 let start_fn = Callee::def(ccx, start_def_id, empty_substs).reify(ccx).val;
                 let args = {
                     let opaque_rust_main =
index 17d08cd6c2f292a756cebdd5799d9846fab995dc..1013c5d64b6097039119d3942c98d4ad6b413c38 100644 (file)
@@ -383,7 +383,7 @@ pub fn trans_fn_pointer_shim<'a, 'tcx>(
     let llfn = declare::define_internal_fn(ccx, &function_name, tuple_fn_ty);
 
     //
-    let empty_substs = tcx.mk_substs(Substs::trans_empty());
+    let empty_substs = tcx.mk_substs(Substs::empty());
     let (block_arena, fcx): (TypedArena<_>, FunctionContext);
     block_arena = TypedArena::new();
     fcx = FunctionContext::new(ccx, llfn, fn_ty, None, empty_substs, &block_arena);
index 2036feb31a25bcd84975e46c6a7bb73c6099f46a..dbabc3f54c594d6be009db4db2f7ff676174be6f 100644 (file)
@@ -144,10 +144,7 @@ fn get_or_create_closure_declaration<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
     // duplicate declarations
     let tcx = ccx.tcx();
     let substs = tcx.erase_regions(substs);
-    let instance = Instance {
-        def: closure_id,
-        params: &substs.func_substs.types
-    };
+    let instance = Instance::new(closure_id, &substs.func_substs);
 
     if let Some(&llfn) = ccx.instances().borrow().get(&instance) {
         debug!("get_or_create_closure_declaration(): found closure {:?}: {:?}",
index 2c996c032ca90eedab2b94092626834e3877b51f..ab8f7d6bec3d5830ed835bdad8fbb793bb14d6d8 100644 (file)
@@ -241,7 +241,7 @@ fn hash<H: Hasher>(&self, s: &mut H) {
             TransItem::Fn(instance) => {
                 1u8.hash(s);
                 instance.def.hash(s);
-                (instance.params as *const _ as usize).hash(s);
+                (instance.substs as *const _ as usize).hash(s);
             }
             TransItem::Static(node_id) => {
                 2u8.hash(s);
@@ -285,7 +285,6 @@ fn collect_roots<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
             mode: mode,
             output: &mut roots,
             enclosing_item: None,
-            trans_empty_substs: ccx.tcx().mk_substs(Substs::trans_empty()),
         };
 
         ccx.tcx().map.krate().visit_all_items(&mut visitor);
@@ -331,10 +330,7 @@ fn collect_items_rec<'a, 'tcx: 'a>(ccx: &CrateContext<'a, 'tcx>,
                 ccx: ccx,
                 mir: &mir,
                 output: &mut neighbors,
-                param_substs: ccx.tcx().mk_substs(Substs {
-                    types: instance.params.clone(),
-                    regions: subst::ErasedRegions
-                })
+                param_substs: instance.substs
             };
 
             visitor.visit_mir(&mir);
@@ -437,7 +433,7 @@ fn visit_rvalue(&mut self, rvalue: &mir::Rvalue<'tcx>) {
                 let exchange_malloc_fn_trans_item =
                     create_fn_trans_item(self.ccx,
                                          exchange_malloc_fn_def_id,
-                                         &Substs::trans_empty(),
+                                         &Substs::empty(),
                                          self.param_substs);
 
                 self.output.push(exchange_malloc_fn_trans_item);
@@ -569,8 +565,8 @@ fn find_drop_glue_neighbors<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
         let exchange_free_fn_trans_item =
             create_fn_trans_item(ccx,
                                  exchange_free_fn_def_id,
-                                 &Substs::trans_empty(),
-                                 &Substs::trans_empty());
+                                 &Substs::empty(),
+                                 &Substs::empty());
 
         output.push(exchange_free_fn_trans_item);
     }
@@ -592,7 +588,7 @@ fn find_drop_glue_neighbors<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
                                    .unwrap();
 
         let self_type_substs = ccx.tcx().mk_substs(
-            Substs::trans_empty().with_self_ty(ty));
+            Substs::empty().with_self_ty(ty));
 
         let trait_ref = ty::TraitRef {
             def_id: drop_trait_def_id,
@@ -608,7 +604,7 @@ fn find_drop_glue_neighbors<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
             let trans_item = create_fn_trans_item(ccx,
                                                   destructor_did,
                                                   substs,
-                                                  &Substs::trans_empty());
+                                                  &Substs::empty());
             output.push(trans_item);
         }
     }
@@ -875,10 +871,9 @@ fn create_fn_trans_item<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
                                                            fn_substs);
     let concrete_substs = ccx.tcx().erase_regions(&concrete_substs);
 
-    let trans_item = TransItem::Fn(Instance {
-        def: def_id,
-        params: &ccx.tcx().mk_substs(concrete_substs).types,
-    });
+    let trans_item =
+        TransItem::Fn(Instance::new(def_id,
+                                    &ccx.tcx().mk_substs(concrete_substs)));
 
     return trans_item;
 }
@@ -914,7 +909,7 @@ fn create_trans_items_for_vtable_methods<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
                                 Some(create_fn_trans_item(ccx,
                                                           impl_method.method.def_id,
                                                           &impl_method.substs,
-                                                          &Substs::trans_empty()))
+                                                          &Substs::empty()))
                             } else {
                                 None
                             }
@@ -938,7 +933,6 @@ struct RootCollector<'b, 'a: 'b, 'tcx: 'a + 'b> {
     mode: TransItemCollectionMode,
     output: &'b mut Vec<TransItem<'tcx>>,
     enclosing_item: Option<&'tcx hir::Item>,
-    trans_empty_substs: &'tcx Substs<'tcx>
 }
 
 impl<'b, 'a, 'v> hir_visit::Visitor<'v> for RootCollector<'b, 'a, 'v> {
@@ -962,7 +956,6 @@ fn visit_item(&mut self, item: &'v hir::Item) {
                 if self.mode == TransItemCollectionMode::Eager {
                     create_trans_items_for_default_impls(self.ccx,
                                                          item,
-                                                         self.trans_empty_substs,
                                                          self.output);
                 }
             }
@@ -1049,7 +1042,6 @@ fn visit_impl_item(&mut self, ii: &'v hir::ImplItem) {
 
 fn create_trans_items_for_default_impls<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
                                                   item: &'tcx hir::Item,
-                                                  trans_empty_substs: &'tcx Substs<'tcx>,
                                                   output: &mut Vec<TransItem<'tcx>>) {
     match item.node {
         hir::ItemImpl(_,
@@ -1098,10 +1090,11 @@ fn create_trans_items_for_default_impls<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
                     }
 
                     if can_have_local_instance(ccx, default_impl.def_id) {
+                        let empty_substs = ccx.tcx().mk_substs(ccx.tcx().erase_regions(mth.substs));
                         let item = create_fn_trans_item(ccx,
                                                         default_impl.def_id,
                                                         callee_substs,
-                                                        trans_empty_substs);
+                                                        empty_substs);
                         output.push(item);
                     }
                 }
@@ -1328,7 +1321,7 @@ fn push_instance_as_string<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
                                      instance: Instance<'tcx>,
                                      output: &mut String) {
     push_item_name(ccx, instance.def, output);
-    push_type_params(ccx, instance.params, &[], output);
+    push_type_params(ccx, &instance.substs.types, &[], output);
 }
 
 fn def_id_to_string(ccx: &CrateContext, def_id: DefId) -> String {
@@ -1386,7 +1379,7 @@ fn to_raw_string(&self) -> String {
             TransItem::Fn(instance) => {
                 format!("Fn({:?}, {})",
                          instance.def,
-                         instance.params as *const _ as usize)
+                         instance.substs as *const _ as usize)
             }
             TransItem::Static(id) => {
                 format!("Static({:?})", id)
index a1ba05840a1aea503d1fd02024dfdb9a53538086..7e6b24969100bef944bee105a2e692e8eb398399 100644 (file)
@@ -272,7 +272,7 @@ fn get_const_val<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
                            param_substs: &'tcx Substs<'tcx>)
                            -> Result<ValueRef, ConstEvalFailure> {
     let expr = get_const_expr(ccx, def_id, ref_expr, param_substs);
-    let empty_substs = ccx.tcx().mk_substs(Substs::trans_empty());
+    let empty_substs = ccx.tcx().mk_substs(Substs::empty());
     match get_const_expr_as_global(ccx, expr, ConstQualif::empty(), empty_substs, TrueConst::Yes) {
         Err(Runtime(err)) => {
             ccx.tcx().sess.span_err(expr.span, &err.description());
@@ -1148,7 +1148,7 @@ pub fn trans_static(ccx: &CrateContext,
         let def_id = ccx.tcx().map.local_def_id(id);
         let datum = get_static(ccx, def_id);
 
-        let empty_substs = ccx.tcx().mk_substs(Substs::trans_empty());
+        let empty_substs = ccx.tcx().mk_substs(Substs::empty());
         let (v, _) = const_expr(
             ccx,
             expr,
index 8f5572f5c4e0ed904f805c623e02017edf352598..637eb394672a41726ddd61da4b66e3f35d665622 100644 (file)
@@ -28,7 +28,7 @@
 use trans::monomorphize::Instance;
 use trans::collector::{TransItem, TransItemState};
 use trans::type_::{Type, TypeNames};
-use middle::subst::Substs;
+use middle::subst::{Substs, VecPerParamSpace};
 use middle::ty::{self, Ty, TyCtxt};
 use session::config::NoDebugInfo;
 use session::Session;
@@ -551,7 +551,6 @@ pub fn local(&self) -> &'b LocalCrateContext<'tcx> {
         self.local
     }
 
-
     /// Get a (possibly) different `CrateContext` from the same
     /// `SharedCrateContext`.
     pub fn rotate(&self) -> CrateContext<'b, 'tcx> {
@@ -856,6 +855,29 @@ pub fn record_translation_item_as_generated(&self, cgi: TransItem<'tcx>) {
             codegen_items.insert(cgi, TransItemState::NotPredictedButGenerated);
         }
     }
+
+    /// Given the node-id of some local item that has no type
+    /// parameters, make a suitable "empty substs" for it.
+    pub fn empty_substs_for_node_id(&self, item_node_id: ast::NodeId)
+                                    -> &'tcx Substs<'tcx> {
+        let item_def_id = self.tcx().map.local_def_id(item_node_id);
+        self.empty_substs_for_def_id(item_def_id)
+    }
+
+    /// Given the def-id of some item that has no type parameters, make
+    /// a suitable "empty substs" for it.
+    pub fn empty_substs_for_def_id(&self, item_def_id: DefId) -> &'tcx Substs<'tcx> {
+        let scheme = self.tcx().lookup_item_type(item_def_id);
+        self.empty_substs_for_scheme(&scheme)
+    }
+
+    pub fn empty_substs_for_scheme(&self, scheme: &ty::TypeScheme<'tcx>)
+                                   -> &'tcx Substs<'tcx> {
+        assert!(scheme.generics.types.is_empty());
+        self.tcx().mk_substs(
+            Substs::new(VecPerParamSpace::empty(),
+                        scheme.generics.regions.map(|_| ty::ReStatic)))
+    }
 }
 
 pub struct TypeOfDepthLock<'a, 'tcx: 'a>(&'a LocalCrateContext<'tcx>);
index abcd703f33ba39f626de0e780e328c899e5dc96b..fe98fa290211ce69fa100dd6fd9a433ccff316bd 100644 (file)
@@ -176,7 +176,7 @@ pub fn trans_into<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
                 hir::ExprPath(..) => {
                     match bcx.def(expr.id) {
                         Def::Const(did) | Def::AssociatedConst(did) => {
-                            let empty_substs = bcx.tcx().mk_substs(Substs::trans_empty());
+                            let empty_substs = bcx.tcx().mk_substs(Substs::empty());
                             let const_expr = consts::get_const_expr(bcx.ccx(), did, expr,
                                                                     empty_substs);
                             // Temporarily get cleanup scopes out of the way,
index 4ca5fb07c98259a68237af43b58b4fda4dbc782d..de4b1ba858a6c21b8e67c37a29bf935a84570657 100644 (file)
@@ -267,7 +267,7 @@ fn get_drop_glue_core<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
 
     let _s = StatRecorder::new(ccx, format!("drop {:?}", t));
 
-    let empty_substs = tcx.mk_substs(Substs::trans_empty());
+    let empty_substs = ccx.tcx().mk_substs(Substs::empty());
     let (arena, fcx): (TypedArena<_>, FunctionContext);
     arena = TypedArena::new();
     fcx = FunctionContext::new(ccx, llfn, fn_ty, None, empty_substs, &arena);
@@ -358,7 +358,7 @@ fn trans_struct_drop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
 
     let trait_ref = ty::Binder(ty::TraitRef {
         def_id: tcx.lang_items.drop_trait().unwrap(),
-        substs: tcx.mk_substs(Substs::trans_empty().with_self_ty(t))
+        substs: tcx.mk_substs(Substs::empty().with_self_ty(t))
     });
     let vtbl = match fulfill_obligation(bcx.ccx(), DUMMY_SP, trait_ref) {
         traits::VtableImpl(data) => data,
index ad32870444a22d0804ee0125739631ce73077fd3..2a5acde6ed80b5049c6c415d1fc30a9b1a92ae1d 100644 (file)
@@ -70,7 +70,7 @@ fn instantiate_inline(ccx: &CrateContext, fn_id: DefId) -> Option<DefId> {
                         // performance.
                         AvailableExternallyLinkage
                     };
-                    let empty_substs = tcx.mk_substs(Substs::trans_empty());
+                    let empty_substs = tcx.mk_substs(Substs::empty());
                     let def_id = tcx.map.local_def_id(item.id);
                     let llfn = Callee::def(ccx, def_id, empty_substs).reify(ccx).val;
                     SetLinkage(llfn, linkage);
@@ -144,7 +144,7 @@ fn instantiate_inline(ccx: &CrateContext, fn_id: DefId) -> Option<DefId> {
                 let impl_tpt = tcx.lookup_item_type(impl_did);
                 if impl_tpt.generics.types.is_empty() &&
                         sig.generics.ty_params.is_empty() {
-                    let empty_substs = tcx.mk_substs(Substs::trans_empty());
+                    let empty_substs = ccx.empty_substs_for_node_id(impl_item.id);
                     let def_id = tcx.map.local_def_id(impl_item.id);
                     let llfn = Callee::def(ccx, def_id, empty_substs).reify(ccx).val;
                     trans_fn(ccx,
index 05b8086de131441ecb0a53e3397726c00b83df70..9bc07c6cd862679bbe07a19d3083331c3607bbcf 100644 (file)
@@ -1298,7 +1298,7 @@ fn gen_fn<'a, 'tcx>(fcx: &FunctionContext<'a, 'tcx>,
         sig: ty::Binder(sig)
     });
     let llfn = declare::define_internal_fn(ccx, name, rust_fn_ty);
-    let empty_substs = ccx.tcx().mk_substs(Substs::trans_empty());
+    let empty_substs = ccx.tcx().mk_substs(Substs::empty());
     let (fcx, block_arena);
     block_arena = TypedArena::new();
     fcx = FunctionContext::new(ccx, llfn, fn_ty, None, empty_substs, &block_arena);
index 30560ec05c46946851b60f15a64fb230207aac50..ae619ceb30b0113d43f4dd34b40a55d4f9ac8222 100644 (file)
@@ -15,7 +15,7 @@
 use llvm::{ValueRef, get_params};
 use middle::def_id::DefId;
 use middle::infer;
-use middle::subst::{Subst, Substs};
+use middle::subst::{FnSpace, Subst, Substs};
 use middle::subst;
 use middle::traits::{self, ProjectionMode};
 use trans::abi::FnType;
@@ -92,7 +92,7 @@ pub fn trans_object_shim<'a, 'tcx>(ccx: &'a CrateContext<'a, 'tcx>,
     let function_name = link::mangle_internal_name_by_type_and_seq(ccx, method_ty, "object_shim");
     let llfn = declare::define_internal_fn(ccx, &function_name, method_ty);
 
-    let empty_substs = tcx.mk_substs(Substs::trans_empty());
+    let empty_substs = tcx.mk_substs(Substs::empty());
     let (block_arena, fcx): (TypedArena<_>, FunctionContext);
     block_arena = TypedArena::new();
     fcx = FunctionContext::new(ccx, llfn, fn_ty, None, empty_substs, &block_arena);
@@ -268,9 +268,17 @@ pub fn get_vtable_methods<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
             debug!("get_vtable_methods: trait_method_type={:?}",
                    trait_method_type);
 
+            // the method may have some early-bound lifetimes, add
+            // regions for those
+            let num_dummy_regions = trait_method_type.generics.regions.len(FnSpace);
+            let dummy_regions = vec![ty::ReStatic; num_dummy_regions];
+            let method_substs = substs.clone()
+                                      .with_method(vec![], dummy_regions);
+            let method_substs = tcx.mk_substs(method_substs);
+
             // The substitutions we have are on the impl, so we grab
             // the method type from the impl to substitute into.
-            let mth = get_impl_method(tcx, impl_id, substs, name);
+            let mth = get_impl_method(tcx, impl_id, method_substs, name);
 
             debug!("get_vtable_methods: mth={:?}", mth);
 
index 2e75439ffc3292ed75668a717a4e19e861f23ebe..63fb8c5fb5e1c4326dbbf5d550fc1f7bf2518963 100644 (file)
@@ -45,10 +45,7 @@ pub fn monomorphic_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
 
     let _icx = push_ctxt("monomorphic_fn");
 
-    let instance = Instance {
-        def: fn_id,
-        params: &psubsts.types
-    };
+    let instance = Instance::new(fn_id, psubsts);
 
     let item_ty = ccx.tcx().lookup_item_type(fn_id).ty;
 
@@ -179,26 +176,24 @@ pub fn monomorphic_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
 #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
 pub struct Instance<'tcx> {
     pub def: DefId,
-    pub params: &'tcx subst::VecPerParamSpace<Ty<'tcx>>
+    pub substs: &'tcx Substs<'tcx>,
 }
 
 impl<'tcx> fmt::Display for Instance<'tcx> {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        let substs = Substs {
-            types: self.params.clone(),
-            regions: subst::ErasedRegions
-        };
-        ppaux::parameterized(f, &substs, self.def, ppaux::Ns::Value, &[],
+        ppaux::parameterized(f, &self.substs, self.def, ppaux::Ns::Value, &[],
                              |tcx| tcx.lookup_item_type(self.def).generics)
     }
 }
 
 impl<'tcx> Instance<'tcx> {
+    pub fn new(def_id: DefId, substs: &'tcx Substs<'tcx>)
+               -> Instance<'tcx> {
+        assert!(substs.regions.iter().all(|&r| r == ty::ReStatic));
+        Instance { def: def_id, substs: substs }
+    }
     pub fn mono(tcx: &TyCtxt<'tcx>, def_id: DefId) -> Instance<'tcx> {
-        Instance {
-            def: def_id,
-            params: &tcx.mk_substs(Substs::trans_empty()).types
-        }
+        Instance::new(def_id, &tcx.mk_substs(Substs::empty()))
     }
 }
 
index 67bd79bb57eb304574e44e2b425415a964a03ec6..159ff90b509554d8bc64323b03449ccd7bb0c4b5 100644 (file)
@@ -411,7 +411,7 @@ fn create_substs_for_ast_path<'tcx>(
            decl_generics, self_ty, types_provided,
            region_substs);
 
-    assert_eq!(region_substs.regions().len(TypeSpace), decl_generics.regions.len(TypeSpace));
+    assert_eq!(region_substs.regions.len(TypeSpace), decl_generics.regions.len(TypeSpace));
     assert!(region_substs.types.is_empty());
 
     // Convert the type parameters supplied by the user.
index ee5dbd032f3ee7c5389fa95043f46f797e90abc9..3e59f0ba73a81d205e2da05d9d656010ea1e470f 100644 (file)
@@ -180,7 +180,7 @@ pub fn compare_impl_method<'tcx>(tcx: &TyCtxt<'tcx>,
         trait_to_impl_substs
         .subst(tcx, impl_to_skol_substs)
         .with_method(impl_to_skol_substs.types.get_slice(subst::FnSpace).to_vec(),
-                     impl_to_skol_substs.regions().get_slice(subst::FnSpace).to_vec());
+                     impl_to_skol_substs.regions.get_slice(subst::FnSpace).to_vec());
     debug!("compare_impl_method: trait_to_skol_substs={:?}",
            trait_to_skol_substs);
 
@@ -439,7 +439,7 @@ pub fn compare_const_impl<'tcx>(tcx: &TyCtxt<'tcx>,
         trait_to_impl_substs
         .subst(tcx, impl_to_skol_substs)
         .with_method(impl_to_skol_substs.types.get_slice(subst::FnSpace).to_vec(),
-                     impl_to_skol_substs.regions().get_slice(subst::FnSpace).to_vec());
+                     impl_to_skol_substs.regions.get_slice(subst::FnSpace).to_vec());
     debug!("compare_const_impl: trait_to_skol_substs={:?}",
            trait_to_skol_substs);
 
index f4268deee37c5a381517ba0a52feaf836ee1ed48..aa4e1d0b52908e8bbf5f9c06e690dd9ce5b8d70e 100644 (file)
@@ -334,7 +334,7 @@ fn instantiate_method_substs(&mut self,
                     .generics.regions.get_slice(subst::FnSpace));
 
         let subst::Substs { types, regions } = substs;
-        let regions = regions.map(|r| r.with_slice(subst::FnSpace, &method_regions));
+        let regions = regions.with_slice(subst::FnSpace, &method_regions);
         let mut final_substs = subst::Substs { types: types, regions: regions };
 
         if num_supplied_types == 0 {
index b522de8d13586399c29fd680d8e36290072b220c..5f7f9703b10596fe699cb361446b75c630cc5d1e 100644 (file)
@@ -505,11 +505,11 @@ fn assemble_inherent_candidates_from_param(&mut self,
                 assert_eq!(m.generics.types.get_slice(subst::TypeSpace).len(),
                            trait_ref.substs.types.get_slice(subst::TypeSpace).len());
                 assert_eq!(m.generics.regions.get_slice(subst::TypeSpace).len(),
-                           trait_ref.substs.regions().get_slice(subst::TypeSpace).len());
+                           trait_ref.substs.regions.get_slice(subst::TypeSpace).len());
                 assert_eq!(m.generics.types.get_slice(subst::SelfSpace).len(),
                            trait_ref.substs.types.get_slice(subst::SelfSpace).len());
                 assert_eq!(m.generics.regions.get_slice(subst::SelfSpace).len(),
-                           trait_ref.substs.regions().get_slice(subst::SelfSpace).len());
+                           trait_ref.substs.regions.get_slice(subst::SelfSpace).len());
             }
 
             // Because this trait derives from a where-clause, it
@@ -1194,7 +1194,7 @@ fn xform_method_self_ty(&self,
         // method yet. So create fresh variables here for those too,
         // if there are any.
         assert_eq!(substs.types.len(subst::FnSpace), 0);
-        assert_eq!(substs.regions().len(subst::FnSpace), 0);
+        assert_eq!(substs.regions.len(subst::FnSpace), 0);
 
         if self.mode == Mode::Path {
             return impl_ty;
index 903fc458d818564c891688938095021698c30b94..6eb663e6047910c4a0dd4b31232bcacc1d698df4 100644 (file)
@@ -4431,7 +4431,7 @@ pub fn instantiate_path<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
         assert_eq!(substs.types.len(space), type_defs.len(space));
 
         adjust_region_parameters(fcx, span, space, region_defs, &mut substs);
-        assert_eq!(substs.regions().len(space), region_defs.len(space));
+        assert_eq!(substs.regions.len(space), region_defs.len(space));
     }
 
     // The things we are substituting into the type should not contain
@@ -4459,7 +4459,7 @@ pub fn instantiate_path<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
         let impl_scheme = fcx.tcx().lookup_item_type(impl_def_id);
         assert_eq!(substs.types.len(subst::TypeSpace),
                    impl_scheme.generics.types.len(subst::TypeSpace));
-        assert_eq!(substs.regions().len(subst::TypeSpace),
+        assert_eq!(substs.regions.len(subst::TypeSpace),
                    impl_scheme.generics.regions.len(subst::TypeSpace));
 
         let impl_ty = fcx.instantiate_type_scheme(span, &substs, &impl_scheme.ty);
@@ -4550,11 +4550,11 @@ fn push_explicit_angle_bracketed_parameters_from_segment_to_substs<'a, 'tcx>(
 
         {
             let region_count = region_defs.len(space);
-            assert_eq!(substs.regions().len(space), 0);
+            assert_eq!(substs.regions.len(space), 0);
             for (i, lifetime) in data.lifetimes.iter().enumerate() {
                 let r = ast_region_to_region(fcx.tcx(), lifetime);
                 if i < region_count {
-                    substs.mut_regions().push(space, r);
+                    substs.regions.push(space, r);
                 } else if i == region_count {
                     span_err!(fcx.tcx().sess, lifetime.span, E0088,
                         "too many lifetime parameters provided: \
@@ -4563,7 +4563,7 @@ fn push_explicit_angle_bracketed_parameters_from_segment_to_substs<'a, 'tcx>(
                         if region_count == 1 {""} else {"s"},
                         data.lifetimes.len(),
                         if data.lifetimes.len() == 1 {""} else {"s"});
-                    substs.mut_regions().truncate(space, 0);
+                    substs.regions.truncate(space, 0);
                     break;
                 }
             }
@@ -4686,7 +4686,7 @@ fn adjust_region_parameters(
         defs: &VecPerParamSpace<ty::RegionParameterDef>,
         substs: &mut Substs)
     {
-        let provided_len = substs.mut_regions().len(space);
+        let provided_len = substs.regions.len(space);
         let desired = defs.get_slice(space);
 
         // Enforced by `push_explicit_parameters_from_segment_to_substs()`.
@@ -4694,7 +4694,7 @@ fn adjust_region_parameters(
 
         // If nothing was provided, just use inference variables.
         if provided_len == 0 {
-            substs.mut_regions().replace(
+            substs.regions.replace(
                 space,
                 fcx.infcx().region_vars_for_defs(span, desired));
             return;
@@ -4715,7 +4715,7 @@ fn adjust_region_parameters(
             provided_len,
             if provided_len == 1 {""} else {"s"});
 
-        substs.mut_regions().replace(
+        substs.regions.replace(
             space,
             fcx.infcx().region_vars_for_defs(span, desired));
     }
index e428fc927f05cf925caded37c7dfa77a947a0c63..fb4870bce87653027c2ab7beb122b719eb8fbe2c 100644 (file)
@@ -1496,7 +1496,7 @@ pub fn substs_wf_in_scope<'a,'tcx>(rcx: &mut Rcx<'a,'tcx>,
 
     let origin = infer::ParameterInScope(origin, expr_span);
 
-    for &region in substs.regions() {
+    for &region in &substs.regions {
         rcx.fcx.mk_subr(origin.clone(), expr_region, region);
     }
 
@@ -1624,7 +1624,7 @@ fn projection_must_outlive<'a, 'tcx>(rcx: &Rcx<'a, 'tcx>,
     // edges, which winds up enforcing the same condition.
     let needs_infer = {
         projection_ty.trait_ref.substs.types.iter().any(|t| t.needs_infer()) ||
-            projection_ty.trait_ref.substs.regions().iter().any(|r| r.needs_infer())
+            projection_ty.trait_ref.substs.regions.iter().any(|r| r.needs_infer())
     };
     if env_bounds.is_empty() && needs_infer {
         debug!("projection_must_outlive: no declared bounds");
@@ -1633,7 +1633,7 @@ fn projection_must_outlive<'a, 'tcx>(rcx: &Rcx<'a, 'tcx>,
             type_must_outlive(rcx, origin.clone(), component_ty, region);
         }
 
-        for &r in projection_ty.trait_ref.substs.regions() {
+        for &r in &projection_ty.trait_ref.substs.regions {
             rcx.fcx.mk_subr(origin.clone(), region, r);
         }
 
@@ -1650,7 +1650,7 @@ fn projection_must_outlive<'a, 'tcx>(rcx: &Rcx<'a, 'tcx>,
     if !env_bounds.is_empty() && env_bounds[1..].iter().all(|b| *b == env_bounds[0]) {
         let unique_bound = env_bounds[0];
         debug!("projection_must_outlive: unique declared bound = {:?}", unique_bound);
-        if projection_ty.trait_ref.substs.regions()
+        if projection_ty.trait_ref.substs.regions
                                          .iter()
                                          .any(|r| env_bounds.contains(r))
         {
index 907ee15c41ba0238ba1c6e3ad725f2c248ca29ab..4446063e0c7bc537e0958875b849bf01cd367062 100644 (file)
@@ -81,7 +81,7 @@ fn parameters_for_type_shallow<'tcx>(ty: Ty<'tcx>) -> Vec<Parameter> {
 }
 
 fn parameters_for_regions_in_substs(substs: &subst::Substs) -> Vec<Parameter> {
-    substs.regions()
+    substs.regions
           .iter()
           .filter_map(|r| parameters_for_region(r))
           .collect()
index aecc588c3e286c3bebdf3a2615341a942b08a590..5c74e9096f3a7ec3be7546d35d39993ef83f3554 100644 (file)
@@ -477,7 +477,7 @@ fn add_constraints_from_substs(&mut self,
                 self.declared_variance(p.def_id, def_id,
                                        RegionParam, p.space, p.index as usize);
             let variance_i = self.xform(variance, variance_decl);
-            let substs_r = *substs.regions().get(p.space, p.index as usize);
+            let substs_r = *substs.regions.get(p.space, p.index as usize);
             self.add_constraints_from_region(generics, substs_r, variance_i);
         }
     }
index cca027ca17a016d1b32eadea1796af2cad471855..15aeca9204a642e4ef08d68bb00375ac21aea206 100644 (file)
@@ -606,7 +606,7 @@ fn clean(&self, cx: &DocContext) -> (Vec<TyParamBound>, Vec<TypeBinding>) {
 
 fn external_path_params(cx: &DocContext, trait_did: Option<DefId>,
                         bindings: Vec<TypeBinding>, substs: &subst::Substs) -> PathParameters {
-    let lifetimes = substs.regions().get_slice(subst::TypeSpace)
+    let lifetimes = substs.regions.get_slice(subst::TypeSpace)
                     .iter()
                     .filter_map(|v| v.clean(cx))
                     .collect();
@@ -739,7 +739,7 @@ fn clean(&self, cx: &DocContext) -> TyParamBound {
 impl<'tcx> Clean<Option<Vec<TyParamBound>>> for subst::Substs<'tcx> {
     fn clean(&self, cx: &DocContext) -> Option<Vec<TyParamBound>> {
         let mut v = Vec::new();
-        v.extend(self.regions().iter().filter_map(|r| r.clean(cx)).map(RegionBound));
+        v.extend(self.regions.iter().filter_map(|r| r.clean(cx)).map(RegionBound));
         v.extend(self.types.iter().map(|t| TraitBound(PolyTrait {
             trait_: t.clean(cx),
             lifetimes: vec![]