12
12
// refers to rules defined in RFC 1214 (`OutlivesFooBar`), so see that
13
13
// RFC for reference.
14
14
15
+ use smallvec:: SmallVec ;
15
16
use ty:: { self , Ty , TyCtxt , TypeFoldable } ;
16
17
17
18
#[ derive( Debug ) ]
@@ -55,17 +56,15 @@ pub enum Component<'tcx> {
55
56
}
56
57
57
58
impl < ' 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
59
60
/// `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) ;
66
65
}
67
66
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 ] > ) {
69
68
// Descend through the types, looking for the various "base"
70
69
// components and collecting them into `out`. This is not written
71
70
// with `collect()` because of the need to sometimes skip subtrees
@@ -164,7 +163,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
164
163
// list is maintained explicitly, because bound regions
165
164
// themselves can be readily identified.
166
165
167
- push_region_constraints ( out , ty . regions ( ) ) ;
166
+ push_region_constraints ( ty , out ) ;
168
167
for subty in ty. walk_shallow ( ) {
169
168
self . compute_components ( subty, out) ;
170
169
}
@@ -173,15 +172,17 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
173
172
}
174
173
175
174
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) ;
178
177
for subty in ty. walk_shallow ( ) {
179
178
self . compute_components ( subty, & mut temp) ;
180
179
}
181
- temp
180
+ temp. into_iter ( ) . collect ( )
182
181
}
183
182
}
184
183
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) ;
186
187
out. extend ( regions. iter ( ) . filter ( |& r| !r. is_late_bound ( ) ) . map ( |r| Component :: Region ( r) ) ) ;
187
188
}
0 commit comments