Skip to content

Commit ba1b5ee

Browse files
committed
Simplify impl of Elaborator now that we don't need stack traces anymore.
1 parent 3b3bb0e commit ba1b5ee

File tree

1 file changed

+12
-44
lines changed

1 file changed

+12
-44
lines changed

src/librustc/middle/traits/util.rs

Lines changed: 12 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,10 @@ impl<'a,'tcx> PredicateSet<'a,'tcx> {
7676
/// 'static`.
7777
pub struct Elaborator<'cx, 'tcx:'cx> {
7878
tcx: &'cx ty::ctxt<'tcx>,
79-
stack: Vec<StackEntry<'tcx>>,
79+
stack: Vec<ty::Predicate<'tcx>>,
8080
visited: PredicateSet<'cx,'tcx>,
8181
}
8282

83-
struct StackEntry<'tcx> {
84-
position: uint,
85-
predicates: Vec<ty::Predicate<'tcx>>,
86-
}
87-
8883
pub fn elaborate_trait_ref<'cx, 'tcx>(
8984
tcx: &'cx ty::ctxt<'tcx>,
9085
trait_ref: ty::PolyTraitRef<'tcx>)
@@ -111,8 +106,7 @@ pub fn elaborate_predicates<'cx, 'tcx>(
111106
{
112107
let mut visited = PredicateSet::new(tcx);
113108
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 }
116110
}
117111

118112
impl<'cx, 'tcx> Elaborator<'cx, 'tcx> {
@@ -134,8 +128,7 @@ impl<'cx, 'tcx> Elaborator<'cx, 'tcx> {
134128
// Sized { }`.
135129
predicates.retain(|r| self.visited.insert(r));
136130

137-
self.stack.push(StackEntry { position: 0,
138-
predicates: predicates });
131+
self.stack.extend(predicates.into_iter());
139132
}
140133
ty::Predicate::Equate(..) => {
141134
// Currently, we do not "elaborate" predicates like
@@ -175,41 +168,16 @@ impl<'cx, 'tcx> Iterator for Elaborator<'cx, 'tcx> {
175168
type Item = ty::Predicate<'tcx>;
176169

177170
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;
211177
}
212-
}
178+
};
179+
self.push(&next_predicate);
180+
return Some(next_predicate);
213181
}
214182
}
215183

0 commit comments

Comments
 (0)