1
Fork 0

Use fulfillment in InferCtxt::evaluate_obligation

This commit is contained in:
Michael Goulet 2023-03-23 19:22:32 +00:00
parent 2bab422393
commit 1680334928
2 changed files with 15 additions and 30 deletions

View file

@ -1,9 +1,8 @@
use rustc_middle::traits::solve::{Certainty, Goal, MaybeCause}; use rustc_infer::traits::{TraitEngine, TraitEngineExt};
use rustc_middle::ty; use rustc_middle::ty;
use crate::infer::canonical::OriginalQueryValues; use crate::infer::canonical::OriginalQueryValues;
use crate::infer::InferCtxt; use crate::infer::InferCtxt;
use crate::solve::InferCtxtEvalExt;
use crate::traits::{EvaluationResult, OverflowError, PredicateObligation, SelectionContext}; use crate::traits::{EvaluationResult, OverflowError, PredicateObligation, SelectionContext};
pub trait InferCtxtExt<'tcx> { pub trait InferCtxtExt<'tcx> {
@ -81,35 +80,20 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
if self.tcx.trait_solver_next() { if self.tcx.trait_solver_next() {
self.probe(|snapshot| { self.probe(|snapshot| {
if let Ok((_, certainty, nested_goals)) = let mut fulfill_cx = crate::solve::FulfillmentCtxt::new();
self.evaluate_root_goal(Goal::new(self.tcx, param_env, obligation.predicate)) fulfill_cx.register_predicate_obligation(self, obligation.clone());
{ // True errors
match certainty { // FIXME(-Ztrait-solver=next): Overflows are reported as ambig here, is that OK?
// If we have nested obligations from instantiating the canonical if !fulfill_cx.select_where_possible(self).is_empty() {
// response from this goal, just treat the response as ambiguous.
//
// FIXME(deferred_projection_equality): We need to process this
// in a loop probably... can't be worse than an ICE though
Certainty::Yes if !nested_goals.is_empty() => {
Ok(EvaluationResult::EvaluatedToAmbig)
}
Certainty::Yes => {
if self.opaque_types_added_in_snapshot(snapshot) {
Ok(EvaluationResult::EvaluatedToOkModuloOpaqueTypes)
} else if self.region_constraints_added_in_snapshot(snapshot).is_some()
{
Ok(EvaluationResult::EvaluatedToOkModuloRegions)
} else {
Ok(EvaluationResult::EvaluatedToOk)
}
}
Certainty::Maybe(MaybeCause::Ambiguity) => {
Ok(EvaluationResult::EvaluatedToAmbig)
}
Certainty::Maybe(MaybeCause::Overflow) => Err(OverflowError::Canonical),
}
} else {
Ok(EvaluationResult::EvaluatedToErr) Ok(EvaluationResult::EvaluatedToErr)
} else if !fulfill_cx.select_all_or_error(self).is_empty() {
Ok(EvaluationResult::EvaluatedToAmbig)
} else if self.opaque_types_added_in_snapshot(snapshot) {
Ok(EvaluationResult::EvaluatedToOkModuloOpaqueTypes)
} else if self.region_constraints_added_in_snapshot(snapshot).is_some() {
Ok(EvaluationResult::EvaluatedToOkModuloRegions)
} else {
Ok(EvaluationResult::EvaluatedToOk)
} }
}) })
} else { } else {

View file

@ -618,6 +618,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
let mut fulfill_cx = crate::solve::FulfillmentCtxt::new(); let mut fulfill_cx = crate::solve::FulfillmentCtxt::new();
fulfill_cx.register_predicate_obligations(self.infcx, predicates); fulfill_cx.register_predicate_obligations(self.infcx, predicates);
// True errors // True errors
// FIXME(-Ztrait-solver=next): Overflows are reported as ambig here, is that OK?
if !fulfill_cx.select_where_possible(self.infcx).is_empty() { if !fulfill_cx.select_where_possible(self.infcx).is_empty() {
return Ok(EvaluatedToErr); return Ok(EvaluatedToErr);
} }