From ba1b5ee1d19de24d311335d3735e5100b47c2cf6 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 23 Feb 2015 15:00:49 -0500 Subject: [PATCH] Simplify impl of Elaborator now that we don't need stack traces anymore. --- src/librustc/middle/traits/util.rs | 56 +++++++----------------------- 1 file changed, 12 insertions(+), 44 deletions(-) diff --git a/src/librustc/middle/traits/util.rs b/src/librustc/middle/traits/util.rs index 7bef5f32475d..1264d92143f4 100644 --- a/src/librustc/middle/traits/util.rs +++ b/src/librustc/middle/traits/util.rs @@ -76,15 +76,10 @@ impl<'a,'tcx> PredicateSet<'a,'tcx> { /// 'static`. pub struct Elaborator<'cx, 'tcx:'cx> { tcx: &'cx ty::ctxt<'tcx>, - stack: Vec>, + stack: Vec>, visited: PredicateSet<'cx,'tcx>, } -struct StackEntry<'tcx> { - position: uint, - predicates: Vec>, -} - pub fn elaborate_trait_ref<'cx, 'tcx>( tcx: &'cx ty::ctxt<'tcx>, trait_ref: ty::PolyTraitRef<'tcx>) @@ -111,8 +106,7 @@ pub fn elaborate_predicates<'cx, 'tcx>( { let mut visited = PredicateSet::new(tcx); predicates.retain(|pred| visited.insert(pred)); - let entry = StackEntry { position: 0, predicates: predicates }; - Elaborator { tcx: tcx, stack: vec![entry], visited: visited } + Elaborator { tcx: tcx, stack: predicates, visited: visited } } impl<'cx, 'tcx> Elaborator<'cx, 'tcx> { @@ -134,8 +128,7 @@ impl<'cx, 'tcx> Elaborator<'cx, 'tcx> { // Sized { }`. predicates.retain(|r| self.visited.insert(r)); - self.stack.push(StackEntry { position: 0, - predicates: predicates }); + self.stack.extend(predicates.into_iter()); } ty::Predicate::Equate(..) => { // Currently, we do not "elaborate" predicates like @@ -175,41 +168,16 @@ impl<'cx, 'tcx> Iterator for Elaborator<'cx, 'tcx> { type Item = ty::Predicate<'tcx>; fn next(&mut self) -> Option> { - loop { - // Extract next item from top-most stack frame, if any. - let next_predicate = match self.stack.last_mut() { - None => { - // No more stack frames. Done. - return None; - } - Some(entry) => { - let p = entry.position; - if p < entry.predicates.len() { - // Still more predicates left in the top stack frame. - entry.position += 1; - - let next_predicate = - entry.predicates[p].clone(); - - Some(next_predicate) - } else { - None - } - } - }; - - match next_predicate { - Some(next_predicate) => { - self.push(&next_predicate); - return Some(next_predicate); - } - - None => { - // Top stack frame is exhausted, pop it. - self.stack.pop(); - } + // Extract next item from top-most stack frame, if any. + let next_predicate = match self.stack.pop() { + Some(predicate) => predicate, + None => { + // No more stack frames. Done. + return None; } - } + }; + self.push(&next_predicate); + return Some(next_predicate); } }