Port existing callers of evaluate_obligation
to the new canonical trait query
Except the one in coherence, which needs support for intercrate mode.
This commit is contained in:
parent
3ab3a9f509
commit
bc16b8e92a
9 changed files with 17 additions and 16 deletions
|
@ -155,6 +155,9 @@ fn overlap<'cx, 'gcx, 'tcx>(selcx: &mut SelectionContext<'cx, 'gcx, 'tcx>,
|
|||
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
|
||||
// the new system supports intercrate mode (which coherence needs).
|
||||
|
||||
if let Some(failing_obligation) = opt_failing_obligation {
|
||||
debug!("overlap: obligation unsatisfiable {:?}", failing_obligation);
|
||||
|
|
|
@ -660,8 +660,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
predicate: ty::Predicate::Trait(predicate),
|
||||
.. obligation.clone()
|
||||
};
|
||||
let mut selcx = SelectionContext::new(self);
|
||||
if selcx.evaluate_obligation(&unit_obligation) {
|
||||
if self.predicate_may_hold(&unit_obligation) {
|
||||
err.note("the trait is implemented for `()`. \
|
||||
Possibly this error has been caused by changes to \
|
||||
Rust's type-inference algorithm \
|
||||
|
@ -877,7 +876,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
.count();
|
||||
|
||||
let mut trait_type = trait_ref.self_ty();
|
||||
let mut selcx = SelectionContext::new(self);
|
||||
|
||||
for refs_remaining in 0..refs_number {
|
||||
if let ty::TypeVariants::TyRef(_, ty::TypeAndMut{ ty: t_type, mutbl: _ }) =
|
||||
|
@ -891,7 +889,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
obligation.param_env,
|
||||
new_trait_ref.to_predicate());
|
||||
|
||||
if selcx.evaluate_obligation(&new_obligation) {
|
||||
if self.predicate_may_hold(&new_obligation) {
|
||||
let sp = self.tcx.sess.codemap()
|
||||
.span_take_while(span, |c| c.is_whitespace() || *c == '&');
|
||||
|
||||
|
@ -1327,7 +1325,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
|
|||
cleaned_pred.to_predicate()
|
||||
);
|
||||
|
||||
selcx.evaluate_obligation(&obligation)
|
||||
self.predicate_may_hold(&obligation)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -333,7 +333,7 @@ fn process_predicate<'a, 'gcx, 'tcx>(
|
|||
if data.is_global() {
|
||||
// no type variables present, can use evaluation for better caching.
|
||||
// FIXME: consider caching errors too.
|
||||
if selcx.evaluate_obligation_conservatively(&obligation) {
|
||||
if selcx.infcx().predicate_must_hold(&obligation) {
|
||||
debug!("selecting trait `{:?}` at depth {} evaluated to holds",
|
||||
data, obligation.recursion_depth);
|
||||
return Ok(Some(vec![]))
|
||||
|
|
|
@ -552,8 +552,7 @@ pub fn type_known_to_meet_bound<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx
|
|||
predicate: trait_ref.to_predicate(),
|
||||
};
|
||||
|
||||
let result = SelectionContext::new(infcx)
|
||||
.evaluate_obligation_conservatively(&obligation);
|
||||
let result = infcx.predicate_must_hold(&obligation);
|
||||
debug!("type_known_to_meet_ty={:?} bound={} => {:?}",
|
||||
ty, infcx.tcx.item_path_str(def_id), result);
|
||||
|
||||
|
|
|
@ -120,15 +120,15 @@ impl<'a, 'gcx, 'tcx> Autoderef<'a, 'gcx, 'tcx> {
|
|||
|
||||
let cause = traits::ObligationCause::misc(self.span, self.fcx.body_id);
|
||||
|
||||
let mut selcx = traits::SelectionContext::new(self.fcx);
|
||||
let obligation = traits::Obligation::new(cause.clone(),
|
||||
self.fcx.param_env,
|
||||
trait_ref.to_predicate());
|
||||
if !selcx.evaluate_obligation(&obligation) {
|
||||
if !self.fcx.predicate_may_hold(&obligation) {
|
||||
debug!("overloaded_deref_ty: cannot match obligation");
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut selcx = traits::SelectionContext::new(self.fcx);
|
||||
let normalized = traits::normalize_projection_type(&mut selcx,
|
||||
self.fcx.param_env,
|
||||
ty::ProjectionTy::from_ref_and_name(
|
||||
|
|
|
@ -277,8 +277,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
poly_trait_ref.to_predicate());
|
||||
|
||||
// Now we want to know if this can be matched
|
||||
let mut selcx = traits::SelectionContext::new(self);
|
||||
if !selcx.evaluate_obligation(&obligation) {
|
||||
if !self.predicate_may_hold(&obligation) {
|
||||
debug!("--> Cannot match obligation");
|
||||
return None; // Cannot be matched, no such method resolution is possible.
|
||||
}
|
||||
|
|
|
@ -1173,7 +1173,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
|
|||
let predicate = trait_ref.to_predicate();
|
||||
let obligation =
|
||||
traits::Obligation::new(cause.clone(), self.param_env, predicate);
|
||||
if !selcx.evaluate_obligation(&obligation) {
|
||||
if !self.predicate_may_hold(&obligation) {
|
||||
if self.probe(|_| self.select_trait_candidate(trait_ref).is_err()) {
|
||||
// This candidate's primary obligation doesn't even
|
||||
// select - don't bother registering anything in
|
||||
|
@ -1201,7 +1201,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
|
|||
// Evaluate those obligations to see if they might possibly hold.
|
||||
for o in candidate_obligations.into_iter().chain(sub_obligations) {
|
||||
let o = self.resolve_type_vars_if_possible(&o);
|
||||
if !selcx.evaluate_obligation(&o) {
|
||||
if !self.predicate_may_hold(&o) {
|
||||
result = ProbeResult::NoMatch;
|
||||
if let &ty::Predicate::Trait(ref pred) = &o.predicate {
|
||||
possibly_unsatisfied_predicates.push(pred.skip_binder().trait_ref);
|
||||
|
|
|
@ -19,7 +19,7 @@ use hir::def::Def;
|
|||
use hir::def_id::{CRATE_DEF_INDEX, DefId};
|
||||
use middle::lang_items::FnOnceTraitLangItem;
|
||||
use namespace::Namespace;
|
||||
use rustc::traits::{Obligation, SelectionContext};
|
||||
use rustc::traits::Obligation;
|
||||
use util::nodemap::FxHashSet;
|
||||
|
||||
use syntax::ast;
|
||||
|
@ -65,7 +65,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||
self.body_id,
|
||||
self.param_env,
|
||||
poly_trait_ref.to_predicate());
|
||||
SelectionContext::new(self).evaluate_obligation(&obligation)
|
||||
self.predicate_may_hold(&obligation)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ error[E0391]: cycle detected when processing `cycle1`
|
|||
LL | fn cycle1() -> impl Clone {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: ...which requires evaluating trait selection obligation `impl std::clone::Clone: std::marker::Send`...
|
||||
note: ...which requires processing `cycle2::{{impl-Trait}}`...
|
||||
--> $DIR/auto-trait-leak.rs:49:16
|
||||
|
|
||||
|
@ -44,6 +45,7 @@ note: ...which requires processing `cycle2`...
|
|||
|
|
||||
LL | fn cycle2() -> impl Clone {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
note: ...which requires evaluating trait selection obligation `impl std::clone::Clone: std::marker::Send`...
|
||||
note: ...which requires processing `cycle1::{{impl-Trait}}`...
|
||||
--> $DIR/auto-trait-leak.rs:42:16
|
||||
|
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue