Skip to content

Commit bc16b8e

Browse files
committed
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 3ab3a9f commit bc16b8e

File tree

9 files changed

+17
-16
lines changed

9 files changed

+17
-16
lines changed

src/librustc/traits/coherence.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ fn overlap<'cx, 'gcx, 'tcx>(selcx: &mut SelectionContext<'cx, 'gcx, 'tcx>,
155155
predicate: p })
156156
.chain(obligations)
157157
.find(|o| !selcx.evaluate_obligation(o));
158+
// FIXME: the call to `selcx.evaluate_obligation` above should be ported
159+
// to the canonical trait query form, `infcx.predicate_may_hold`, once
160+
// the new system supports intercrate mode (which coherence needs).
158161

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

src/librustc/traits/error_reporting.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -660,8 +660,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
660660
predicate: ty::Predicate::Trait(predicate),
661661
.. obligation.clone()
662662
};
663-
let mut selcx = SelectionContext::new(self);
664-
if selcx.evaluate_obligation(&unit_obligation) {
663+
if self.predicate_may_hold(&unit_obligation) {
665664
err.note("the trait is implemented for `()`. \
666665
Possibly this error has been caused by changes to \
667666
Rust's type-inference algorithm \
@@ -877,7 +876,6 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
877876
.count();
878877

879878
let mut trait_type = trait_ref.self_ty();
880-
let mut selcx = SelectionContext::new(self);
881879

882880
for refs_remaining in 0..refs_number {
883881
if let ty::TypeVariants::TyRef(_, ty::TypeAndMut{ ty: t_type, mutbl: _ }) =
@@ -891,7 +889,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
891889
obligation.param_env,
892890
new_trait_ref.to_predicate());
893891

894-
if selcx.evaluate_obligation(&new_obligation) {
892+
if self.predicate_may_hold(&new_obligation) {
895893
let sp = self.tcx.sess.codemap()
896894
.span_take_while(span, |c| c.is_whitespace() || *c == '&');
897895

@@ -1327,7 +1325,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
13271325
cleaned_pred.to_predicate()
13281326
);
13291327

1330-
selcx.evaluate_obligation(&obligation)
1328+
self.predicate_may_hold(&obligation)
13311329
})
13321330
}
13331331

src/librustc/traits/fulfill.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ fn process_predicate<'a, 'gcx, 'tcx>(
333333
if data.is_global() {
334334
// no type variables present, can use evaluation for better caching.
335335
// FIXME: consider caching errors too.
336-
if selcx.evaluate_obligation_conservatively(&obligation) {
336+
if selcx.infcx().predicate_must_hold(&obligation) {
337337
debug!("selecting trait `{:?}` at depth {} evaluated to holds",
338338
data, obligation.recursion_depth);
339339
return Ok(Some(vec![]))

src/librustc/traits/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -552,8 +552,7 @@ pub fn type_known_to_meet_bound<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx
552552
predicate: trait_ref.to_predicate(),
553553
};
554554

555-
let result = SelectionContext::new(infcx)
556-
.evaluate_obligation_conservatively(&obligation);
555+
let result = infcx.predicate_must_hold(&obligation);
557556
debug!("type_known_to_meet_ty={:?} bound={} => {:?}",
558557
ty, infcx.tcx.item_path_str(def_id), result);
559558

src/librustc_typeck/check/autoderef.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,15 @@ 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);
124123
let obligation = traits::Obligation::new(cause.clone(),
125124
self.fcx.param_env,
126125
trait_ref.to_predicate());
127-
if !selcx.evaluate_obligation(&obligation) {
126+
if !self.fcx.predicate_may_hold(&obligation) {
128127
debug!("overloaded_deref_ty: cannot match obligation");
129128
return None;
130129
}
131130

131+
let mut selcx = traits::SelectionContext::new(self.fcx);
132132
let normalized = traits::normalize_projection_type(&mut selcx,
133133
self.fcx.param_env,
134134
ty::ProjectionTy::from_ref_and_name(

src/librustc_typeck/check/method/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
277277
poly_trait_ref.to_predicate());
278278

279279
// Now we want to know if this can be matched
280-
let mut selcx = traits::SelectionContext::new(self);
281-
if !selcx.evaluate_obligation(&obligation) {
280+
if !self.predicate_may_hold(&obligation) {
282281
debug!("--> Cannot match obligation");
283282
return None; // Cannot be matched, no such method resolution is possible.
284283
}

src/librustc_typeck/check/method/probe.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
11731173
let predicate = trait_ref.to_predicate();
11741174
let obligation =
11751175
traits::Obligation::new(cause.clone(), self.param_env, predicate);
1176-
if !selcx.evaluate_obligation(&obligation) {
1176+
if !self.predicate_may_hold(&obligation) {
11771177
if self.probe(|_| self.select_trait_candidate(trait_ref).is_err()) {
11781178
// This candidate's primary obligation doesn't even
11791179
// select - don't bother registering anything in
@@ -1201,7 +1201,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
12011201
// Evaluate those obligations to see if they might possibly hold.
12021202
for o in candidate_obligations.into_iter().chain(sub_obligations) {
12031203
let o = self.resolve_type_vars_if_possible(&o);
1204-
if !selcx.evaluate_obligation(&o) {
1204+
if !self.predicate_may_hold(&o) {
12051205
result = ProbeResult::NoMatch;
12061206
if let &ty::Predicate::Trait(ref pred) = &o.predicate {
12071207
possibly_unsatisfied_predicates.push(pred.skip_binder().trait_ref);

src/librustc_typeck/check/method/suggest.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use hir::def::Def;
1919
use hir::def_id::{CRATE_DEF_INDEX, DefId};
2020
use middle::lang_items::FnOnceTraitLangItem;
2121
use namespace::Namespace;
22-
use rustc::traits::{Obligation, SelectionContext};
22+
use rustc::traits::Obligation;
2323
use util::nodemap::FxHashSet;
2424

2525
use syntax::ast;
@@ -65,7 +65,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
6565
self.body_id,
6666
self.param_env,
6767
poly_trait_ref.to_predicate());
68-
SelectionContext::new(self).evaluate_obligation(&obligation)
68+
self.predicate_may_hold(&obligation)
6969
})
7070
})
7171
}

src/test/ui/impl-trait/auto-trait-leak.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ error[E0391]: cycle detected when processing `cycle1`
3434
LL | fn cycle1() -> impl Clone {
3535
| ^^^^^^^^^^^^^^^^^^^^^^^^^
3636
|
37+
note: ...which requires evaluating trait selection obligation `impl std::clone::Clone: std::marker::Send`...
3738
note: ...which requires processing `cycle2::{{impl-Trait}}`...
3839
--> $DIR/auto-trait-leak.rs:49:16
3940
|
@@ -44,6 +45,7 @@ note: ...which requires processing `cycle2`...
4445
|
4546
LL | fn cycle2() -> impl Clone {
4647
| ^^^^^^^^^^^^^^^^^^^^^^^^^
48+
note: ...which requires evaluating trait selection obligation `impl std::clone::Clone: std::marker::Send`...
4749
note: ...which requires processing `cycle1::{{impl-Trait}}`...
4850
--> $DIR/auto-trait-leak.rs:42:16
4951
|

0 commit comments

Comments
 (0)