Skip to content

Commit

Permalink
introduce evaluate_obligation_conservatively and use it
Browse files Browse the repository at this point in the history
  • Loading branch information
Ariel Ben-Yehuda committed Nov 15, 2015
1 parent 9c6d35d commit 8943d5a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/librustc/middle/traits/mod.rs
Expand Up @@ -340,6 +340,21 @@ pub fn type_known_to_meet_builtin_bound<'a,'tcx>(infcx: &InferCtxt<'a,'tcx>,
ty,
bound);

if !ty.has_infer_types() && !ty.has_closure_types() {
let cause = ObligationCause::misc(span, ast::DUMMY_NODE_ID);
let obligation =
util::predicate_for_builtin_bound(infcx.tcx, cause, bound, 0, ty);
let obligation = match obligation {
Ok(o) => o,
Err(..) => return false
};
let result = SelectionContext::new(infcx)
.evaluate_obligation_conservatively(&obligation);
debug!("type_known_to_meet_builtin_bound: ty={:?} bound={:?} => {:?}",
ty, bound, result);
return result;
}

let mut fulfill_cx = FulfillmentContext::new(false);

// We can use a dummy node-id here because we won't pay any mind
Expand Down
17 changes: 17 additions & 0 deletions src/librustc/middle/traits/select.rs
Expand Up @@ -407,6 +407,23 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
})
}

/// 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
{
debug!("evaluate_obligation_conservatively({:?})",
obligation);

self.infcx.probe(|_| {
self.evaluate_predicate_recursively(TraitObligationStackList::empty(), obligation)
== EvaluatedToOk
})
}


fn evaluate_predicates_recursively<'a,'o,I>(&mut self,
stack: TraitObligationStackList<'o, 'tcx>,
predicates: I)
Expand Down

0 comments on commit 8943d5a

Please sign in to comment.