@@ -76,15 +76,10 @@ impl<'a,'tcx> PredicateSet<'a,'tcx> {
76
76
/// 'static`.
77
77
pub struct Elaborator < ' cx , ' tcx : ' cx > {
78
78
tcx : & ' cx ty:: ctxt < ' tcx > ,
79
- stack : Vec < StackEntry < ' tcx > > ,
79
+ stack : Vec < ty :: Predicate < ' tcx > > ,
80
80
visited : PredicateSet < ' cx , ' tcx > ,
81
81
}
82
82
83
- struct StackEntry < ' tcx > {
84
- position : uint ,
85
- predicates : Vec < ty:: Predicate < ' tcx > > ,
86
- }
87
-
88
83
pub fn elaborate_trait_ref < ' cx , ' tcx > (
89
84
tcx : & ' cx ty:: ctxt < ' tcx > ,
90
85
trait_ref : ty:: PolyTraitRef < ' tcx > )
@@ -111,8 +106,7 @@ pub fn elaborate_predicates<'cx, 'tcx>(
111
106
{
112
107
let mut visited = PredicateSet :: new ( tcx) ;
113
108
predicates. retain ( |pred| visited. insert ( pred) ) ;
114
- let entry = StackEntry { position : 0 , predicates : predicates } ;
115
- Elaborator { tcx : tcx, stack : vec ! [ entry] , visited : visited }
109
+ Elaborator { tcx : tcx, stack : predicates, visited : visited }
116
110
}
117
111
118
112
impl < ' cx , ' tcx > Elaborator < ' cx , ' tcx > {
@@ -134,8 +128,7 @@ impl<'cx, 'tcx> Elaborator<'cx, 'tcx> {
134
128
// Sized { }`.
135
129
predicates. retain ( |r| self . visited . insert ( r) ) ;
136
130
137
- self . stack . push ( StackEntry { position : 0 ,
138
- predicates : predicates } ) ;
131
+ self . stack . extend ( predicates. into_iter ( ) ) ;
139
132
}
140
133
ty:: Predicate :: Equate ( ..) => {
141
134
// Currently, we do not "elaborate" predicates like
@@ -175,41 +168,16 @@ impl<'cx, 'tcx> Iterator for Elaborator<'cx, 'tcx> {
175
168
type Item = ty:: Predicate < ' tcx > ;
176
169
177
170
fn next ( & mut self ) -> Option < ty:: Predicate < ' tcx > > {
178
- loop {
179
- // Extract next item from top-most stack frame, if any.
180
- let next_predicate = match self . stack . last_mut ( ) {
181
- None => {
182
- // No more stack frames. Done.
183
- return None ;
184
- }
185
- Some ( entry) => {
186
- let p = entry. position ;
187
- if p < entry. predicates . len ( ) {
188
- // Still more predicates left in the top stack frame.
189
- entry. position += 1 ;
190
-
191
- let next_predicate =
192
- entry. predicates [ p] . clone ( ) ;
193
-
194
- Some ( next_predicate)
195
- } else {
196
- None
197
- }
198
- }
199
- } ;
200
-
201
- match next_predicate {
202
- Some ( next_predicate) => {
203
- self . push ( & next_predicate) ;
204
- return Some ( next_predicate) ;
205
- }
206
-
207
- None => {
208
- // Top stack frame is exhausted, pop it.
209
- self . stack . pop ( ) ;
210
- }
171
+ // Extract next item from top-most stack frame, if any.
172
+ let next_predicate = match self . stack . pop ( ) {
173
+ Some ( predicate) => predicate,
174
+ None => {
175
+ // No more stack frames. Done.
176
+ return None ;
211
177
}
212
- }
178
+ } ;
179
+ self . push ( & next_predicate) ;
180
+ return Some ( next_predicate) ;
213
181
}
214
182
}
215
183
0 commit comments