Skip to content

Commit

Permalink
Use fulfillment in InferCtxt::evaluate_obligation
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Mar 23, 2023
1 parent 2bab422 commit 1680334
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use rustc_middle::traits::solve::{Certainty, Goal, MaybeCause};
use rustc_infer::traits::{TraitEngine, TraitEngineExt};
use rustc_middle::ty;

use crate::infer::canonical::OriginalQueryValues;
use crate::infer::InferCtxt;
use crate::solve::InferCtxtEvalExt;
use crate::traits::{EvaluationResult, OverflowError, PredicateObligation, SelectionContext};

pub trait InferCtxtExt<'tcx> {
Expand Down Expand Up @@ -81,35 +80,20 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {

if self.tcx.trait_solver_next() {
self.probe(|snapshot| {
if let Ok((_, certainty, nested_goals)) =
self.evaluate_root_goal(Goal::new(self.tcx, param_env, obligation.predicate))
{
match certainty {
// If we have nested obligations from instantiating the canonical
// 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 {
let mut fulfill_cx = crate::solve::FulfillmentCtxt::new();
fulfill_cx.register_predicate_obligation(self, obligation.clone());
// True errors
// FIXME(-Ztrait-solver=next): Overflows are reported as ambig here, is that OK?
if !fulfill_cx.select_where_possible(self).is_empty() {
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 {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_trait_selection/src/traits/select/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
let mut fulfill_cx = crate::solve::FulfillmentCtxt::new();
fulfill_cx.register_predicate_obligations(self.infcx, predicates);
// 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() {
return Ok(EvaluatedToErr);
}
Expand Down

0 comments on commit 1680334

Please sign in to comment.