1
Fork 0

evaluate: improve and fix recursion depth handling

This commit is contained in:
lcnr 2023-03-14 14:56:16 +01:00
parent 791ce0b7b5
commit c63861b9d5
9 changed files with 60 additions and 95 deletions

View file

@ -8,6 +8,8 @@ mod project;
mod structural_impls;
pub mod util;
use std::cmp;
use hir::def_id::LocalDefId;
use rustc_hir as hir;
use rustc_middle::ty::error::{ExpectedFound, TypeError};
@ -139,6 +141,14 @@ impl<'tcx, O> Obligation<'tcx, O> {
Self::with_depth(tcx, cause, 0, param_env, predicate)
}
/// We often create nested obligations without setting the correct depth.
///
/// To deal with this evaluate and fulfill explicitly update the depth
/// of nested obligations using this function.
pub fn set_depth_from_parent(&mut self, parent_depth: usize) {
self.recursion_depth = cmp::max(parent_depth + 1, self.recursion_depth);
}
pub fn with_depth(
tcx: TyCtxt<'tcx>,
cause: ObligationCause<'tcx>,