diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index a9bdb909bdcf7..999ef97683ca8 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -221,7 +221,7 @@ fn pred_known_to_hold_modulo_regions<'tcx>( if result.must_apply_modulo_regions() { true - } else if result.may_apply() { + } else if result.may_apply() && !infcx.next_trait_solver() { // Sometimes obligations are ambiguous because the recursive evaluator // is not smart enough, so we fall back to fulfillment when we're not certain // that an obligation holds or not. Even still, we must make sure that diff --git a/compiler/rustc_trait_selection/src/traits/query/evaluate_obligation.rs b/compiler/rustc_trait_selection/src/traits/query/evaluate_obligation.rs index 9e1a2a3e7d286..ca8c3a531bd5e 100644 --- a/compiler/rustc_trait_selection/src/traits/query/evaluate_obligation.rs +++ b/compiler/rustc_trait_selection/src/traits/query/evaluate_obligation.rs @@ -1,11 +1,12 @@ use rustc_macros::extension; use rustc_middle::span_bug; +use rustc_next_trait_solver::solve::{Certainty, GenerateProofTree, SolverDelegateEvalExt}; +use rustc_span::DUMMY_SP; use crate::infer::InferCtxt; use crate::infer::canonical::OriginalQueryValues; -use crate::traits::{ - EvaluationResult, ObligationCtxt, OverflowError, PredicateObligation, SelectionContext, -}; +use crate::solve::SolverDelegate; +use crate::traits::{EvaluationResult, OverflowError, PredicateObligation, SelectionContext}; #[extension(pub trait InferCtxtExt<'tcx>)] impl<'tcx> InferCtxt<'tcx> { @@ -69,16 +70,14 @@ impl<'tcx> InferCtxt<'tcx> { if self.next_trait_solver() { self.probe(|snapshot| { - let ocx = ObligationCtxt::new(self); - ocx.register_obligation(obligation.clone()); - let mut result = EvaluationResult::EvaluatedToOk; - for error in ocx.select_all_or_error() { - if error.is_true_error() { - return Ok(EvaluationResult::EvaluatedToErr); - } else { - result = result.max(EvaluationResult::EvaluatedToAmbig); - } - } + let mut result = match <&SolverDelegate<'tcx>>::from(self) + .evaluate_root_goal(obligation.as_goal(), GenerateProofTree::No, DUMMY_SP) + .0 + { + Ok((_, Certainty::Yes)) => EvaluationResult::EvaluatedToOk, + Ok((_, Certainty::Maybe(_))) => EvaluationResult::EvaluatedToAmbig, + Err(_) => EvaluationResult::EvaluatedToErr, + }; if self.opaque_types_added_in_snapshot(snapshot) { result = result.max(EvaluationResult::EvaluatedToOkModuloOpaqueTypes); } else if self.region_constraints_added_in_snapshot(snapshot) {