From dbbb42442cdb8fdfa610a03355f8614bd1d08ffb Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 9 Apr 2023 01:10:47 +0000 Subject: [PATCH] EvaluateToAmbig if evaluate_root_obligation does inference --- .../rustc_trait_selection/src/traits/select/mod.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index e4f5a84f424..065e7b1aee4 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -537,14 +537,21 @@ pub fn evaluate_root_obligation( obligation: &PredicateObligation<'tcx>, ) -> Result { self.evaluation_probe(|this| { - if this.tcx().trait_solver_next() { - this.evaluate_predicates_recursively_in_new_solver([obligation.clone()]) + let goal = infcx.resolve_vars_if_possible((obligation.predicate, obligation.param_env)); + let mut result = if this.tcx().trait_solver_next() { + this.evaluate_predicates_recursively_in_new_solver([obligation.clone()])? } else { this.evaluate_predicate_recursively( TraitObligationStackList::empty(&ProvisionalEvaluationCache::default()), obligation.clone(), - ) + )? + }; + // If the predicate has done any inference, then downgrade the + // result to ambiguous. + if this.infcx.shallow_resolve(goal) != goal { + result = result.max(EvaluatedToAmbig); } + Ok(result) }) }