about summary refs log tree commit diff
path: root/compiler/rustc_infer/src/traits/mod.rs
diff options
context:
space:
mode:
authorlcnr <rust@lcnr.de>2023-03-14 14:56:16 +0100
committerlcnr <rust@lcnr.de>2023-03-21 09:57:22 +0100
commitc63861b9d5a91b827c5c8164e24ee556dd790bbe (patch)
tree83c9dcd19ef3737fe34160f28f405b1fb45903fa /compiler/rustc_infer/src/traits/mod.rs
parent791ce0b7b5d03649bc9014d5b0abb78f3c6f2cfd (diff)
downloadrust-c63861b9d5a91b827c5c8164e24ee556dd790bbe.tar.gz
rust-c63861b9d5a91b827c5c8164e24ee556dd790bbe.zip
evaluate: improve and fix recursion depth handling
Diffstat (limited to 'compiler/rustc_infer/src/traits/mod.rs')
-rw-r--r--compiler/rustc_infer/src/traits/mod.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/compiler/rustc_infer/src/traits/mod.rs b/compiler/rustc_infer/src/traits/mod.rs
index 77c67c14ecc..dd9b2e548c7 100644
--- a/compiler/rustc_infer/src/traits/mod.rs
+++ b/compiler/rustc_infer/src/traits/mod.rs
@@ -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>,