Skip to content

Commit e257271

Browse files
aravind-pgnikomatsakis
authored andcommitted
Port existing callers of evaluate_obligation to the new canonical trait query
Except the one in coherence, which needs support for intercrate mode.
1 parent 2d0113f commit e257271

File tree

8 files changed

+16
-40
lines changed

8 files changed

+16
-40
lines changed

src/librustc/traits/coherence.rs

+3
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ fn overlap<'cx, 'gcx, 'tcx>(selcx: &mut SelectionContext<'cx, 'gcx, 'tcx>,
157157
predicate: p })
158158
.chain(obligations)
159159
.find(|o| !selcx.evaluate_obligation(o));
160+
// FIXME: the call to `selcx.evaluate_obligation` above should be ported
161+
// to the canonical trait query form, `infcx.predicate_may_hold`, once
162+
// the new system supports intercrate mode (which coherence needs).
160163

161164
if let Some(failing_obligation) = opt_failing_obligation {
162165
debug!("overlap: obligation unsatisfiable {:?}", failing_obligation);

src/librustc/traits/error_reporting.rs

+3-13
Original file line numberDiff line numberDiff line change
@@ -643,12 +643,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
643643
}
644644
trait_pred
645645
});
646-
let unit_obligation = Obligation {
647-
predicate: ty::Predicate::Trait(predicate),
648-
.. obligation.clone()
649-
};
650-
let mut selcx = SelectionContext::new(self);
651-
if selcx.evaluate_obligation(&unit_obligation) {
646+
if self.predicate_may_hold(obligation.param_env,
647+
ty::Predicate::Trait(predicate)) {
652648
err.note("the trait is implemented for `()`. \
653649
Possibly this error has been caused by changes to \
654650
Rust's type-inference algorithm \
@@ -1263,13 +1259,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
12631259
&cleaned_pred
12641260
).value;
12651261

1266-
let obligation = Obligation::new(
1267-
ObligationCause::dummy(),
1268-
param_env,
1269-
cleaned_pred.to_predicate()
1270-
);
1271-
1272-
selcx.evaluate_obligation(&obligation)
1262+
self.predicate_may_hold(param_env, cleaned_pred.to_predicate())
12731263
})
12741264
}
12751265

src/librustc/traits/fulfill.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,8 @@ fn process_predicate<'a, 'gcx, 'tcx>(
330330
if data.is_global() {
331331
// no type variables present, can use evaluation for better caching.
332332
// FIXME: consider caching errors too.
333-
if selcx.evaluate_obligation_conservatively(&obligation) {
333+
if selcx.infcx().predicate_must_hold(obligation.param_env,
334+
obligation.predicate) {
334335
debug!("selecting trait `{:?}` at depth {} evaluated to holds",
335336
data, obligation.recursion_depth);
336337
return Ok(Some(vec![]))

src/librustc/traits/mod.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -512,15 +512,8 @@ pub fn type_known_to_meet_bound<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx
512512
def_id,
513513
substs: infcx.tcx.mk_substs_trait(ty, &[]),
514514
};
515-
let obligation = Obligation {
516-
param_env,
517-
cause: ObligationCause::misc(span, ast::DUMMY_NODE_ID),
518-
recursion_depth: 0,
519-
predicate: trait_ref.to_predicate(),
520-
};
521515

522-
let result = SelectionContext::new(infcx)
523-
.evaluate_obligation_conservatively(&obligation);
516+
let result = infcx.predicate_must_hold(param_env, trait_ref.to_predicate());
524517
debug!("type_known_to_meet_ty={:?} bound={} => {:?}",
525518
ty, infcx.tcx.item_path_str(def_id), result);
526519

src/librustc_typeck/check/autoderef.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,13 @@ impl<'a, 'gcx, 'tcx> Autoderef<'a, 'gcx, 'tcx> {
120120

121121
let cause = traits::ObligationCause::misc(self.span, self.fcx.body_id);
122122

123-
let mut selcx = traits::SelectionContext::new(self.fcx);
124-
let obligation = traits::Obligation::new(cause.clone(),
125-
self.fcx.param_env,
126-
trait_ref.to_predicate());
127-
if !selcx.evaluate_obligation(&obligation) {
123+
if !self.fcx.predicate_may_hold(self.fcx.param_env,
124+
trait_ref.to_predicate()) {
128125
debug!("overloaded_deref_ty: cannot match obligation");
129126
return None;
130127
}
131128

129+
let mut selcx = traits::SelectionContext::new(self.fcx);
132130
let normalized = traits::normalize_projection_type(&mut selcx,
133131
self.fcx.param_env,
134132
ty::ProjectionTy::from_ref_and_name(

src/librustc_typeck/check/method/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
272272
poly_trait_ref.to_predicate());
273273

274274
// Now we want to know if this can be matched
275-
let mut selcx = traits::SelectionContext::new(self);
276-
if !selcx.evaluate_obligation(&obligation) {
275+
if !self.predicate_may_hold(self.param_env, poly_trait_ref.to_predicate()) {
277276
debug!("--> Cannot match obligation");
278277
return None; // Cannot be matched, no such method resolution is possible.
279278
}

src/librustc_typeck/check/method/probe.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1079,9 +1079,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
10791079

10801080
TraitCandidate(trait_ref) => {
10811081
let predicate = trait_ref.to_predicate();
1082-
let obligation =
1083-
traits::Obligation::new(cause.clone(), self.param_env, predicate);
1084-
if !selcx.evaluate_obligation(&obligation) {
1082+
if !self.predicate_may_hold(self.param_env, predicate) {
10851083
if self.probe(|_| self.select_trait_candidate(trait_ref).is_err()) {
10861084
// This candidate's primary obligation doesn't even
10871085
// select - don't bother registering anything in
@@ -1109,7 +1107,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
11091107
// Evaluate those obligations to see if they might possibly hold.
11101108
for o in candidate_obligations.into_iter().chain(sub_obligations) {
11111109
let o = self.resolve_type_vars_if_possible(&o);
1112-
if !selcx.evaluate_obligation(&o) {
1110+
if !self.predicate_may_hold(o.param_env, o.predicate) {
11131111
result = ProbeResult::NoMatch;
11141112
if let &ty::Predicate::Trait(ref pred) = &o.predicate {
11151113
possibly_unsatisfied_predicates.push(pred.0.trait_ref);

src/librustc_typeck/check/method/suggest.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use hir::def::Def;
1818
use hir::def_id::{CRATE_DEF_INDEX, DefId};
1919
use middle::lang_items::FnOnceTraitLangItem;
2020
use namespace::Namespace;
21-
use rustc::traits::{Obligation, SelectionContext};
2221
use util::nodemap::FxHashSet;
2322

2423
use syntax::ast;
@@ -58,12 +57,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
5857
TypeVariableOrigin::MiscVariable(span))]);
5958
let trait_ref = ty::TraitRef::new(fn_once, fn_once_substs);
6059
let poly_trait_ref = trait_ref.to_poly_trait_ref();
61-
let obligation =
62-
Obligation::misc(span,
63-
self.body_id,
64-
self.param_env,
65-
poly_trait_ref.to_predicate());
66-
SelectionContext::new(self).evaluate_obligation(&obligation)
60+
self.predicate_may_hold(self.param_env, poly_trait_ref.to_predicate())
6761
})
6862
})
6963
}

0 commit comments

Comments
 (0)