about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2024-03-26 13:16:19 -0400
committerMichael Goulet <michael@errs.io>2024-04-21 20:10:12 -0400
commit9d4f1d8b7eb3ac14dd1e3ba4f286a5db2c4232c5 (patch)
treefb19f5d3aa44b47df48557776a3769a60a33c7f5
parentd9fec1321acf9c397781ca0dd6f130b4d100fe0b (diff)
downloadrust-9d4f1d8b7eb3ac14dd1e3ba4f286a5db2c4232c5.tar.gz
rust-9d4f1d8b7eb3ac14dd1e3ba4f286a5db2c4232c5.zip
Check that predicate may hold BEFORE registering it in ocx
-rw-r--r--compiler/rustc_hir_typeck/src/method/probe.rs15
1 files changed, 13 insertions, 2 deletions
diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs
index 49210209520..1dcda06a349 100644
--- a/compiler/rustc_hir_typeck/src/method/probe.rs
+++ b/compiler/rustc_hir_typeck/src/method/probe.rs
@@ -31,6 +31,7 @@ use rustc_span::edit_distance::{
 };
 use rustc_span::symbol::sym;
 use rustc_span::{symbol::Ident, Span, Symbol, DUMMY_SP};
+use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
 use rustc_trait_selection::traits::query::method_autoderef::MethodAutoderefBadTy;
 use rustc_trait_selection::traits::query::method_autoderef::{
     CandidateStep, MethodAutoderefStepsResult,
@@ -1450,12 +1451,22 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
                             return ProbeResult::NoMatch;
                         }
                     }
-                    ocx.register_obligation(traits::Obligation::new(
+                    let obligation = traits::Obligation::new(
                         self.tcx,
                         cause.clone(),
                         self.param_env,
                         ty::Binder::dummy(trait_ref),
-                    ));
+                    );
+
+                    // FIXME(-Znext-solver): We only need this hack to deal with fatal
+                    // overflow in the old solver.
+                    if self.infcx.next_trait_solver() || self.infcx.predicate_may_hold(&obligation)
+                    {
+                        ocx.register_obligation(obligation);
+                    } else {
+                        result = ProbeResult::NoMatch;
+                    }
+
                     trait_predicate = Some(ty::Binder::dummy(trait_ref).to_predicate(self.tcx));
                 }
                 ObjectCandidate(poly_trait_ref) | WhereClauseCandidate(poly_trait_ref) => {