Skip to content

Commit 1680334

Browse files
Use fulfillment in InferCtxt::evaluate_obligation
1 parent 2bab422 commit 1680334

File tree

2 files changed

+15
-30
lines changed

2 files changed

+15
-30
lines changed

compiler/rustc_trait_selection/src/traits/query/evaluate_obligation.rs

+14-30
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
use rustc_middle::traits::solve::{Certainty, Goal, MaybeCause};
1+
use rustc_infer::traits::{TraitEngine, TraitEngineExt};
22
use rustc_middle::ty;
33

44
use crate::infer::canonical::OriginalQueryValues;
55
use crate::infer::InferCtxt;
6-
use crate::solve::InferCtxtEvalExt;
76
use crate::traits::{EvaluationResult, OverflowError, PredicateObligation, SelectionContext};
87

98
pub trait InferCtxtExt<'tcx> {
@@ -81,35 +80,20 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
8180

8281
if self.tcx.trait_solver_next() {
8382
self.probe(|snapshot| {
84-
if let Ok((_, certainty, nested_goals)) =
85-
self.evaluate_root_goal(Goal::new(self.tcx, param_env, obligation.predicate))
86-
{
87-
match certainty {
88-
// If we have nested obligations from instantiating the canonical
89-
// response from this goal, just treat the response as ambiguous.
90-
//
91-
// FIXME(deferred_projection_equality): We need to process this
92-
// in a loop probably... can't be worse than an ICE though
93-
Certainty::Yes if !nested_goals.is_empty() => {
94-
Ok(EvaluationResult::EvaluatedToAmbig)
95-
}
96-
Certainty::Yes => {
97-
if self.opaque_types_added_in_snapshot(snapshot) {
98-
Ok(EvaluationResult::EvaluatedToOkModuloOpaqueTypes)
99-
} else if self.region_constraints_added_in_snapshot(snapshot).is_some()
100-
{
101-
Ok(EvaluationResult::EvaluatedToOkModuloRegions)
102-
} else {
103-
Ok(EvaluationResult::EvaluatedToOk)
104-
}
105-
}
106-
Certainty::Maybe(MaybeCause::Ambiguity) => {
107-
Ok(EvaluationResult::EvaluatedToAmbig)
108-
}
109-
Certainty::Maybe(MaybeCause::Overflow) => Err(OverflowError::Canonical),
110-
}
111-
} else {
83+
let mut fulfill_cx = crate::solve::FulfillmentCtxt::new();
84+
fulfill_cx.register_predicate_obligation(self, obligation.clone());
85+
// True errors
86+
// FIXME(-Ztrait-solver=next): Overflows are reported as ambig here, is that OK?
87+
if !fulfill_cx.select_where_possible(self).is_empty() {
11288
Ok(EvaluationResult::EvaluatedToErr)
89+
} else if !fulfill_cx.select_all_or_error(self).is_empty() {
90+
Ok(EvaluationResult::EvaluatedToAmbig)
91+
} else if self.opaque_types_added_in_snapshot(snapshot) {
92+
Ok(EvaluationResult::EvaluatedToOkModuloOpaqueTypes)
93+
} else if self.region_constraints_added_in_snapshot(snapshot).is_some() {
94+
Ok(EvaluationResult::EvaluatedToOkModuloRegions)
95+
} else {
96+
Ok(EvaluationResult::EvaluatedToOk)
11397
}
11498
})
11599
} else {

compiler/rustc_trait_selection/src/traits/select/mod.rs

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

0 commit comments

Comments
 (0)