1111// Type substitutions.
1212
1313pub use self :: ParamSpace :: * ;
14- pub use self :: RegionSubsts :: * ;
1514
1615use middle:: cstore;
1716use middle:: def_id:: DefId ;
@@ -34,24 +33,15 @@ use syntax::codemap::{Span, DUMMY_SP};
3433#[ derive( Clone , PartialEq , Eq , Hash ) ]
3534pub struct Substs < ' tcx > {
3635 pub types : VecPerParamSpace < Ty < ' tcx > > ,
37- pub regions : RegionSubsts ,
38- }
39-
40- /// Represents the values to use when substituting lifetime parameters.
41- /// If the value is `ErasedRegions`, then this subst is occurring during
42- /// trans, and all region parameters will be replaced with `ty::ReStatic`.
43- #[ derive( Clone , PartialEq , Eq , Hash ) ]
44- pub enum RegionSubsts {
45- ErasedRegions ,
46- NonerasedRegions ( VecPerParamSpace < ty:: Region > )
36+ pub regions : VecPerParamSpace < ty:: Region > ,
4737}
4838
4939impl < ' tcx > Substs < ' tcx > {
5040 pub fn new ( t : VecPerParamSpace < Ty < ' tcx > > ,
5141 r : VecPerParamSpace < ty:: Region > )
5242 -> Substs < ' tcx >
5343 {
54- Substs { types : t, regions : NonerasedRegions ( r ) }
44+ Substs { types : t, regions : r }
5545 }
5646
5747 pub fn new_type ( t : Vec < Ty < ' tcx > > ,
@@ -71,32 +61,15 @@ impl<'tcx> Substs<'tcx> {
7161 VecPerParamSpace :: new ( r, Vec :: new ( ) , Vec :: new ( ) ) )
7262 }
7363
74- pub fn erased ( t : VecPerParamSpace < Ty < ' tcx > > ) -> Substs < ' tcx >
75- {
76- Substs { types : t, regions : ErasedRegions }
77- }
78-
7964 pub fn empty ( ) -> Substs < ' tcx > {
8065 Substs {
8166 types : VecPerParamSpace :: empty ( ) ,
82- regions : NonerasedRegions ( VecPerParamSpace :: empty ( ) ) ,
83- }
84- }
85-
86- pub fn trans_empty ( ) -> Substs < ' tcx > {
87- Substs {
88- types : VecPerParamSpace :: empty ( ) ,
89- regions : ErasedRegions
67+ regions : VecPerParamSpace :: empty ( ) ,
9068 }
9169 }
9270
9371 pub fn is_noop ( & self ) -> bool {
94- let regions_is_noop = match self . regions {
95- ErasedRegions => false , // may be used to canonicalize
96- NonerasedRegions ( ref regions) => regions. is_empty ( ) ,
97- } ;
98-
99- regions_is_noop && self . types . is_empty ( )
72+ self . regions . is_empty ( ) && self . types . is_empty ( )
10073 }
10174
10275 pub fn type_for_def ( & self , ty_param_def : & ty:: TypeParameterDef ) -> Ty < ' tcx > {
@@ -115,26 +88,9 @@ impl<'tcx> Substs<'tcx> {
11588 }
11689
11790 pub fn erase_regions ( self ) -> Substs < ' tcx > {
118- let Substs { types, regions : _ } = self ;
119- Substs { types : types, regions : ErasedRegions }
120- }
121-
122- /// Since ErasedRegions are only to be used in trans, most of the compiler can use this method
123- /// to easily access the set of region substitutions.
124- pub fn regions < ' a > ( & ' a self ) -> & ' a VecPerParamSpace < ty:: Region > {
125- match self . regions {
126- ErasedRegions => panic ! ( "Erased regions only expected in trans" ) ,
127- NonerasedRegions ( ref r) => r
128- }
129- }
130-
131- /// Since ErasedRegions are only to be used in trans, most of the compiler can use this method
132- /// to easily access the set of region substitutions.
133- pub fn mut_regions < ' a > ( & ' a mut self ) -> & ' a mut VecPerParamSpace < ty:: Region > {
134- match self . regions {
135- ErasedRegions => panic ! ( "Erased regions only expected in trans" ) ,
136- NonerasedRegions ( ref mut r) => r
137- }
91+ let Substs { types, regions } = self ;
92+ let regions = regions. map ( |_| ty:: ReStatic ) ;
93+ Substs { types : types, regions : regions }
13894 }
13995
14096 pub fn with_method ( self ,
@@ -144,7 +100,7 @@ impl<'tcx> Substs<'tcx> {
144100 {
145101 let Substs { types, regions } = self ;
146102 let types = types. with_slice ( FnSpace , & m_types) ;
147- let regions = regions. map ( |r| r . with_slice ( FnSpace , & m_regions) ) ;
103+ let regions = regions. with_slice ( FnSpace , & m_regions) ;
148104 Substs { types : types, regions : regions }
149105 }
150106
@@ -154,27 +110,23 @@ impl<'tcx> Substs<'tcx> {
154110 {
155111 let Substs { types, regions } = self . clone ( ) ;
156112 let types = types. with_slice ( FnSpace , meth_substs. types . get_slice ( FnSpace ) ) ;
157- let regions = regions. map ( |r| {
158- r. with_slice ( FnSpace , meth_substs. regions ( ) . get_slice ( FnSpace ) )
159- } ) ;
113+ let regions = regions. with_slice ( FnSpace , meth_substs. regions . get_slice ( FnSpace ) ) ;
160114 Substs { types : types, regions : regions }
161115 }
162116
163117 pub fn with_method_from_subst ( self , other : & Substs < ' tcx > ) -> Substs < ' tcx > {
164118 let Substs { types, regions } = self ;
165119 let types = types. with_slice ( FnSpace , other. types . get_slice ( FnSpace ) ) ;
166- let regions = regions. map ( |r| {
167- r. with_slice ( FnSpace , other. regions ( ) . get_slice ( FnSpace ) )
168- } ) ;
120+ let regions = regions. with_slice ( FnSpace , other. regions . get_slice ( FnSpace ) ) ;
169121 Substs { types : types, regions : regions }
170122 }
171123
172124 /// Creates a trait-ref out of this substs, ignoring the FnSpace substs
173125 pub fn to_trait_ref ( & self , tcx : & TyCtxt < ' tcx > , trait_id : DefId )
174126 -> ty:: TraitRef < ' tcx > {
175- let Substs { mut types, regions } = self . clone ( ) ;
127+ let Substs { mut types, mut regions } = self . clone ( ) ;
176128 types. truncate ( FnSpace , 0 ) ;
177- let regions = regions . map ( | mut r| { r . truncate ( FnSpace , 0 ) ; r } ) ;
129+ regions. truncate ( FnSpace , 0 ) ;
178130
179131 ty:: TraitRef {
180132 def_id : trait_id,
@@ -212,24 +164,6 @@ impl<'tcx> Decodable for &'tcx Substs<'tcx> {
212164 }
213165}
214166
215- impl RegionSubsts {
216- pub fn map < F > ( self , op : F ) -> RegionSubsts where
217- F : FnOnce ( VecPerParamSpace < ty:: Region > ) -> VecPerParamSpace < ty:: Region > ,
218- {
219- match self {
220- ErasedRegions => ErasedRegions ,
221- NonerasedRegions ( r) => NonerasedRegions ( op ( r) )
222- }
223- }
224-
225- pub fn is_erased ( & self ) -> bool {
226- match * self {
227- ErasedRegions => true ,
228- NonerasedRegions ( _) => false ,
229- }
230- }
231- }
232-
233167///////////////////////////////////////////////////////////////////////////
234168// ParamSpace
235169
@@ -664,26 +598,22 @@ impl<'a, 'tcx> TypeFolder<'tcx> for SubstFolder<'a, 'tcx> {
664598 // the specialized routine `ty::replace_late_regions()`.
665599 match r {
666600 ty:: ReEarlyBound ( data) => {
667- match self . substs . regions {
668- ErasedRegions => ty:: ReStatic ,
669- NonerasedRegions ( ref regions) =>
670- match regions. opt_get ( data. space , data. index as usize ) {
671- Some ( & r) => {
672- self . shift_region_through_binders ( r)
673- }
674- None => {
675- let span = self . span . unwrap_or ( DUMMY_SP ) ;
676- self . tcx ( ) . sess . span_bug (
677- span,
678- & format ! ( "Type parameter out of range \
679- when substituting in region {} (root type={:?}) \
680- (space={:?}, index={})",
681- data. name,
682- self . root_ty,
683- data. space,
684- data. index) ) ;
685- }
686- }
601+ match self . substs . regions . opt_get ( data. space , data. index as usize ) {
602+ Some ( & r) => {
603+ self . shift_region_through_binders ( r)
604+ }
605+ None => {
606+ let span = self . span . unwrap_or ( DUMMY_SP ) ;
607+ self . tcx ( ) . sess . span_bug (
608+ span,
609+ & format ! ( "Region parameter out of range \
610+ when substituting in region {} (root type={:?}) \
611+ (space={:?}, index={})",
612+ data. name,
613+ self . root_ty,
614+ data. space,
615+ data. index) ) ;
616+ }
687617 }
688618 }
689619 _ => r
0 commit comments