From e64a7bf64b70a9630d1ba8741665158d91f4cca7 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 6 Jun 2019 13:32:00 -0400 Subject: [PATCH] introduce a stack depth --- src/librustc/traits/select.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/librustc/traits/select.rs b/src/librustc/traits/select.rs index 503e0db548e4a..d8ffc55ada5c8 100644 --- a/src/librustc/traits/select.rs +++ b/src/librustc/traits/select.rs @@ -185,6 +185,9 @@ struct TraitObligationStack<'prev, 'tcx: 'prev> { in_cycle: Cell, previous: TraitObligationStackList<'prev, 'tcx>, + + /// Number of parent frames plus one -- so the topmost frame has depth 1. + depth: usize, } #[derive(Clone, Default)] @@ -662,8 +665,10 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { obligation: &PredicateObligation<'tcx>, ) -> Result { self.evaluation_probe(|this| { - this.evaluate_predicate_recursively(TraitObligationStackList::empty(), - obligation.clone()) + this.evaluate_predicate_recursively( + TraitObligationStackList::empty(), + obligation.clone(), + ) }) } @@ -3743,6 +3748,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { fresh_trait_ref, in_cycle: Cell::new(false), previous: previous_stack, + depth: previous_stack.depth() + 1, } } @@ -3957,6 +3963,14 @@ impl<'o, 'tcx> TraitObligationStackList<'o, 'tcx> { fn head(&self) -> Option<&'o TraitObligationStack<'o, 'tcx>> { self.head } + + fn depth(&self) -> usize { + if let Some(head) = self.head { + head.depth + } else { + 0 + } + } } impl<'o, 'tcx> Iterator for TraitObligationStackList<'o, 'tcx> {