1212// refers to rules defined in RFC 1214 (`OutlivesFooBar`), so see that
1313// RFC for reference.
1414
15+ use smallvec:: SmallVec ;
1516use ty:: { self , Ty , TyCtxt , TypeFoldable } ;
1617
1718#[ derive( Debug ) ]
@@ -55,17 +56,15 @@ pub enum Component<'tcx> {
5556}
5657
5758impl < ' a , ' gcx , ' tcx > TyCtxt < ' a , ' gcx , ' tcx > {
58- /// Returns all the things that must outlive `'a` for the condition
59+ /// Push onto `out` all the things that must outlive `'a` for the condition
5960 /// `ty0: 'a` to hold. Note that `ty0` must be a **fully resolved type**.
60- pub fn outlives_components ( & self , ty0 : Ty < ' tcx > )
61- -> Vec < Component < ' tcx > > {
62- let mut components = vec ! [ ] ;
63- self . compute_components ( ty0, & mut components) ;
64- debug ! ( "components({:?}) = {:?}" , ty0, components) ;
65- components
61+ pub fn push_outlives_components ( & self , ty0 : Ty < ' tcx > ,
62+ out : & mut SmallVec < [ Component < ' tcx > ; 4 ] > ) {
63+ self . compute_components ( ty0, out) ;
64+ debug ! ( "components({:?}) = {:?}" , ty0, out) ;
6665 }
6766
68- fn compute_components ( & self , ty : Ty < ' tcx > , out : & mut Vec < Component < ' tcx > > ) {
67+ fn compute_components ( & self , ty : Ty < ' tcx > , out : & mut SmallVec < [ Component < ' tcx > ; 4 ] > ) {
6968 // Descend through the types, looking for the various "base"
7069 // components and collecting them into `out`. This is not written
7170 // with `collect()` because of the need to sometimes skip subtrees
@@ -164,7 +163,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
164163 // list is maintained explicitly, because bound regions
165164 // themselves can be readily identified.
166165
167- push_region_constraints ( out , ty . regions ( ) ) ;
166+ push_region_constraints ( ty , out ) ;
168167 for subty in ty. walk_shallow ( ) {
169168 self . compute_components ( subty, out) ;
170169 }
@@ -173,15 +172,17 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
173172 }
174173
175174 fn capture_components ( & self , ty : Ty < ' tcx > ) -> Vec < Component < ' tcx > > {
176- let mut temp = vec ! [ ] ;
177- push_region_constraints ( & mut temp, ty . regions ( ) ) ;
175+ let mut temp = smallvec ! [ ] ;
176+ push_region_constraints ( ty , & mut temp) ;
178177 for subty in ty. walk_shallow ( ) {
179178 self . compute_components ( subty, & mut temp) ;
180179 }
181- temp
180+ temp. into_iter ( ) . collect ( )
182181 }
183182}
184183
185- fn push_region_constraints < ' tcx > ( out : & mut Vec < Component < ' tcx > > , regions : Vec < ty:: Region < ' tcx > > ) {
184+ fn push_region_constraints < ' tcx > ( ty : Ty < ' tcx > , out : & mut SmallVec < [ Component < ' tcx > ; 4 ] > ) {
185+ let mut regions = smallvec ! [ ] ;
186+ ty. push_regions ( & mut regions) ;
186187 out. extend ( regions. iter ( ) . filter ( |& r| !r. is_late_bound ( ) ) . map ( |r| Component :: Region ( r) ) ) ;
187188}
0 commit comments