about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2023-04-09 01:10:47 +0000
committerMichael Goulet <michael@errs.io>2023-05-12 18:40:28 +0000
commitdbbb42442cdb8fdfa610a03355f8614bd1d08ffb (patch)
treea2a6837c56a7dc19b456313553afea4fcf399b50
parent077fc26f0acfa54e9c580534616c17ffc279a9d4 (diff)
downloadrust-dbbb42442cdb8fdfa610a03355f8614bd1d08ffb.tar.gz
rust-dbbb42442cdb8fdfa610a03355f8614bd1d08ffb.zip
EvaluateToAmbig if evaluate_root_obligation does inference
-rw-r--r--compiler/rustc_trait_selection/src/traits/select/mod.rs13
1 files 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 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
         obligation: &PredicateObligation<'tcx>,
     ) -> Result<EvaluationResult, OverflowError> {
         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)
         })
     }