Skip to content

Commit

Permalink
Simplify trait selector's evaluation API
Browse files Browse the repository at this point in the history
  • Loading branch information
aravind-pg authored and nikomatsakis committed Mar 19, 2018
1 parent e257271 commit 2ee933d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 36 deletions.
6 changes: 3 additions & 3 deletions src/librustc/traits/coherence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ fn overlap<'cx, 'gcx, 'tcx>(selcx: &mut SelectionContext<'cx, 'gcx, 'tcx>,
recursion_depth: 0,
predicate: p })
.chain(obligations)
.find(|o| !selcx.evaluate_obligation(o));
// FIXME: the call to `selcx.evaluate_obligation` above should be ported
// to the canonical trait query form, `infcx.predicate_may_hold`, once
.find(|o| !selcx.evaluate_obligation(o).may_apply());
// FIXME: the call to `selcx.evaluate_obligation().may_apply` above should be
// ported to the canonical trait query form, `infcx.predicate_may_hold`, once
// the new system supports intercrate mode (which coherence needs).

if let Some(failing_obligation) = opt_failing_obligation {
Expand Down
36 changes: 4 additions & 32 deletions src/librustc/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,42 +552,14 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
// The result is "true" if the obligation *may* hold and "false" if
// we can be sure it does not.

/// Evaluates whether the obligation `obligation` can be satisfied (by any means).
/// Evaluates whether the obligation `obligation` can be satisfied and returns
/// an `EvaluationResult`.
pub fn evaluate_obligation(&mut self,
obligation: &PredicateObligation<'tcx>)
-> bool
{
debug!("evaluate_obligation({:?})",
obligation);

self.probe(|this, _| {
this.evaluate_predicate_recursively(TraitObligationStackList::empty(), obligation)
.may_apply()
})
}

/// Evaluates whether the obligation `obligation` can be satisfied,
/// and returns `false` if not certain. However, this is not entirely
/// accurate if inference variables are involved.
pub fn evaluate_obligation_conservatively(&mut self,
obligation: &PredicateObligation<'tcx>)
-> bool
-> EvaluationResult
{
debug!("evaluate_obligation_conservatively({:?})",
obligation);

self.probe(|this, _| {
this.evaluate_predicate_recursively(TraitObligationStackList::empty(), obligation)
== EvaluatedToOk
})
}
debug!("evaluate_obligation({:?})", obligation);

/// Evaluates whether the obligation `obligation` can be satisfied and returns
/// an `EvaluationResult`.
pub fn evaluate_obligation_recursively(&mut self,
obligation: &PredicateObligation<'tcx>)
-> EvaluationResult
{
self.probe(|this, _| {
this.evaluate_predicate_recursively(TraitObligationStackList::empty(), obligation)
})
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_traits/evaluate_obligation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ crate fn evaluate_obligation<'tcx>(
let mut selcx = SelectionContext::new(&infcx);
let obligation = Obligation::new(ObligationCause::dummy(), param_env, predicate);

selcx.evaluate_obligation_recursively(&obligation)
selcx.evaluate_obligation(&obligation)
})
}

0 comments on commit 2ee933d

Please # to comment.