Skip to content

Commit fef14ff

Browse files
Check that predicate may hold BEFORE registering it in ocx
1 parent 85aa98d commit fef14ff

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
@@ -30,6 +30,7 @@ use rustc_span::edit_distance::{
3030
};
3131
use rustc_span::symbol::sym;
3232
use rustc_span::{symbol::Ident, Span, Symbol, DUMMY_SP};
33+
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
3334
use rustc_trait_selection::traits::query::method_autoderef::MethodAutoderefBadTy;
3435
use rustc_trait_selection::traits::query::method_autoderef::{
3536
CandidateStep, MethodAutoderefStepsResult,
@@ -1449,12 +1450,22 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
14491450
return ProbeResult::NoMatch;
14501451
}
14511452
}
1452-
ocx.register_obligation(traits::Obligation::new(
1453+
let obligation = traits::Obligation::new(
14531454
self.tcx,
14541455
cause.clone(),
14551456
self.param_env,
14561457
ty::Binder::dummy(trait_ref),
1457-
));
1458+
);
1459+
1460+
// FIXME(-Znext-solver): We only need this hack to deal with fatal
1461+
// overflow in the old solver.
1462+
if self.infcx.next_trait_solver() || self.infcx.predicate_may_hold(&obligation)
1463+
{
1464+
ocx.register_obligation(obligation);
1465+
} else {
1466+
result = ProbeResult::NoMatch;
1467+
}
1468+
14581469
trait_predicate = Some(ty::Binder::dummy(trait_ref).to_predicate(self.tcx));
14591470
}
14601471
ObjectCandidate(poly_trait_ref) | WhereClauseCandidate(poly_trait_ref) => {

0 commit comments

Comments
 (0)