summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_infer/src/traits/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_infer/src/traits/mod.rs')
-rw-r--r--compiler/rustc_infer/src/traits/mod.rs22
1 files changed, 21 insertions, 1 deletions
diff --git a/compiler/rustc_infer/src/traits/mod.rs b/compiler/rustc_infer/src/traits/mod.rs
index 3a8289966..e01b6caf4 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};
@@ -53,6 +55,12 @@ pub struct Obligation<'tcx, T> {
pub recursion_depth: usize,
}
+impl<'tcx, P> From<Obligation<'tcx, P>> for solve::Goal<'tcx, P> {
+ fn from(value: Obligation<'tcx, P>) -> Self {
+ solve::Goal { param_env: value.param_env, predicate: value.predicate }
+ }
+}
+
pub type PredicateObligation<'tcx> = Obligation<'tcx, ty::Predicate<'tcx>>;
pub type TraitObligation<'tcx> = Obligation<'tcx, ty::PolyTraitPredicate<'tcx>>;
@@ -120,7 +128,11 @@ pub enum FulfillmentErrorCode<'tcx> {
CodeProjectionError(MismatchedProjectionTypes<'tcx>),
CodeSubtypeError(ExpectedFound<Ty<'tcx>>, TypeError<'tcx>), // always comes from a SubtypePredicate
CodeConstEquateError(ExpectedFound<Const<'tcx>>, TypeError<'tcx>),
- CodeAmbiguity,
+ CodeAmbiguity {
+ /// Overflow reported from the new solver `-Ztrait-solver=next`, which will
+ /// be reported as an regular error as opposed to a fatal error.
+ overflow: bool,
+ },
}
impl<'tcx, O> Obligation<'tcx, O> {
@@ -133,6 +145,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>,