Skip to content

Commit 9d4f1d8

Browse files
Check that predicate may hold BEFORE registering it in ocx
1 parent d9fec13 commit 9d4f1d8

File tree

1 file changed

+13
-2
lines changed
  • compiler/rustc_hir_typeck/src/method

1 file changed

+13
-2
lines changed

compiler/rustc_hir_typeck/src/method/probe.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use rustc_span::edit_distance::{
3131
};
3232
use rustc_span::symbol::sym;
3333
use rustc_span::{symbol::Ident, Span, Symbol, DUMMY_SP};
34+
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
3435
use rustc_trait_selection::traits::query::method_autoderef::MethodAutoderefBadTy;
3536
use rustc_trait_selection::traits::query::method_autoderef::{
3637
CandidateStep, MethodAutoderefStepsResult,
@@ -1450,12 +1451,22 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
14501451
return ProbeResult::NoMatch;
14511452
}
14521453
}
1453-
ocx.register_obligation(traits::Obligation::new(
1454+
let obligation = traits::Obligation::new(
14541455
self.tcx,
14551456
cause.clone(),
14561457
self.param_env,
14571458
ty::Binder::dummy(trait_ref),
1458-
));
1459+
);
1460+
1461+
// FIXME(-Znext-solver): We only need this hack to deal with fatal
1462+
// overflow in the old solver.
1463+
if self.infcx.next_trait_solver() || self.infcx.predicate_may_hold(&obligation)
1464+
{
1465+
ocx.register_obligation(obligation);
1466+
} else {
1467+
result = ProbeResult::NoMatch;
1468+
}
1469+
14591470
trait_predicate = Some(ty::Binder::dummy(trait_ref).to_predicate(self.tcx));
14601471
}
14611472
ObjectCandidate(poly_trait_ref) | WhereClauseCandidate(poly_trait_ref) => {

0 commit comments

Comments
 (0)