Skip to content

Commit 8943d5a

Browse files
author
Ariel Ben-Yehuda
committed
introduce evaluate_obligation_conservatively and use it
1 parent 9c6d35d commit 8943d5a

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/librustc/middle/traits/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,21 @@ pub fn type_known_to_meet_builtin_bound<'a,'tcx>(infcx: &InferCtxt<'a,'tcx>,
340340
ty,
341341
bound);
342342

343+
if !ty.has_infer_types() && !ty.has_closure_types() {
344+
let cause = ObligationCause::misc(span, ast::DUMMY_NODE_ID);
345+
let obligation =
346+
util::predicate_for_builtin_bound(infcx.tcx, cause, bound, 0, ty);
347+
let obligation = match obligation {
348+
Ok(o) => o,
349+
Err(..) => return false
350+
};
351+
let result = SelectionContext::new(infcx)
352+
.evaluate_obligation_conservatively(&obligation);
353+
debug!("type_known_to_meet_builtin_bound: ty={:?} bound={:?} => {:?}",
354+
ty, bound, result);
355+
return result;
356+
}
357+
343358
let mut fulfill_cx = FulfillmentContext::new(false);
344359

345360
// We can use a dummy node-id here because we won't pay any mind

src/librustc/middle/traits/select.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,23 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
407407
})
408408
}
409409

410+
/// Evaluates whether the obligation `obligation` can be satisfied,
411+
/// and returns `false` if not certain. However, this is not entirely
412+
/// accurate if inference variables are involved.
413+
pub fn evaluate_obligation_conservatively(&mut self,
414+
obligation: &PredicateObligation<'tcx>)
415+
-> bool
416+
{
417+
debug!("evaluate_obligation_conservatively({:?})",
418+
obligation);
419+
420+
self.infcx.probe(|_| {
421+
self.evaluate_predicate_recursively(TraitObligationStackList::empty(), obligation)
422+
== EvaluatedToOk
423+
})
424+
}
425+
426+
410427
fn evaluate_predicates_recursively<'a,'o,I>(&mut self,
411428
stack: TraitObligationStackList<'o, 'tcx>,
412429
predicates: I)

0 commit comments

Comments
 (0)