Skip to content

Commit e64a7bf

Browse files
committed
introduce a stack depth
1 parent db1dfb2 commit e64a7bf

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/librustc/traits/select.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ struct TraitObligationStack<'prev, 'tcx: 'prev> {
185185
in_cycle: Cell<bool>,
186186

187187
previous: TraitObligationStackList<'prev, 'tcx>,
188+
189+
/// Number of parent frames plus one -- so the topmost frame has depth 1.
190+
depth: usize,
188191
}
189192

190193
#[derive(Clone, Default)]
@@ -662,8 +665,10 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
662665
obligation: &PredicateObligation<'tcx>,
663666
) -> Result<EvaluationResult, OverflowError> {
664667
self.evaluation_probe(|this| {
665-
this.evaluate_predicate_recursively(TraitObligationStackList::empty(),
666-
obligation.clone())
668+
this.evaluate_predicate_recursively(
669+
TraitObligationStackList::empty(),
670+
obligation.clone(),
671+
)
667672
})
668673
}
669674

@@ -3743,6 +3748,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
37433748
fresh_trait_ref,
37443749
in_cycle: Cell::new(false),
37453750
previous: previous_stack,
3751+
depth: previous_stack.depth() + 1,
37463752
}
37473753
}
37483754

@@ -3957,6 +3963,14 @@ impl<'o, 'tcx> TraitObligationStackList<'o, 'tcx> {
39573963
fn head(&self) -> Option<&'o TraitObligationStack<'o, 'tcx>> {
39583964
self.head
39593965
}
3966+
3967+
fn depth(&self) -> usize {
3968+
if let Some(head) = self.head {
3969+
head.depth
3970+
} else {
3971+
0
3972+
}
3973+
}
39603974
}
39613975

39623976
impl<'o, 'tcx> Iterator for TraitObligationStackList<'o, 'tcx> {

0 commit comments

Comments
 (0)