Skip to content

Commit 26e0ea8

Browse files
committed
Use TraitEngine in enter_canonical_trait_query
1 parent da9467d commit 26e0ea8

File tree

5 files changed

+30
-19
lines changed

5 files changed

+30
-19
lines changed

src/librustc/infer/canonical/query_response.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_data_structures::sync::Lrc;
2121
use std::fmt::Debug;
2222
use syntax_pos::DUMMY_SP;
2323
use traits::query::{Fallible, NoSolution};
24-
use traits::{FulfillmentContext, TraitEngine};
24+
use traits::TraitEngine;
2525
use traits::{Obligation, ObligationCause, PredicateObligation};
2626
use ty::fold::TypeFoldable;
2727
use ty::subst::{Kind, UnpackedKind};
@@ -48,7 +48,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxtBuilder<'cx, 'gcx, 'tcx> {
4848
pub fn enter_canonical_trait_query<K, R>(
4949
&'tcx mut self,
5050
canonical_key: &Canonical<'tcx, K>,
51-
operation: impl FnOnce(&InferCtxt<'_, 'gcx, 'tcx>, &mut FulfillmentContext<'tcx>, K)
51+
operation: impl FnOnce(&InferCtxt<'_, 'gcx, 'tcx>, &mut dyn TraitEngine<'tcx>, K)
5252
-> Fallible<R>,
5353
) -> Fallible<CanonicalizedQueryResponse<'gcx, R>>
5454
where
@@ -59,9 +59,13 @@ impl<'cx, 'gcx, 'tcx> InferCtxtBuilder<'cx, 'gcx, 'tcx> {
5959
DUMMY_SP,
6060
canonical_key,
6161
|ref infcx, key, canonical_inference_vars| {
62-
let fulfill_cx = &mut FulfillmentContext::new();
63-
let value = operation(infcx, fulfill_cx, key)?;
64-
infcx.make_canonicalized_query_response(canonical_inference_vars, value, fulfill_cx)
62+
let mut fulfill_cx = TraitEngine::new(infcx.tcx);
63+
let value = operation(infcx, &mut *fulfill_cx, key)?;
64+
infcx.make_canonicalized_query_response(
65+
canonical_inference_vars,
66+
value,
67+
&mut *fulfill_cx
68+
)
6569
},
6670
)
6771
}
@@ -91,7 +95,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
9195
&self,
9296
inference_vars: CanonicalVarValues<'tcx>,
9397
answer: T,
94-
fulfill_cx: &mut FulfillmentContext<'tcx>,
98+
fulfill_cx: &mut dyn TraitEngine<'tcx>,
9599
) -> Fallible<CanonicalizedQueryResponse<'gcx, T>>
96100
where
97101
T: Debug + Lift<'gcx> + TypeFoldable<'tcx>,
@@ -138,7 +142,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
138142
&self,
139143
inference_vars: CanonicalVarValues<'tcx>,
140144
answer: T,
141-
fulfill_cx: &mut FulfillmentContext<'tcx>,
145+
fulfill_cx: &mut dyn TraitEngine<'tcx>,
142146
) -> Result<QueryResponse<'tcx, T>, NoSolution>
143147
where
144148
T: Debug + TypeFoldable<'tcx> + Lift<'gcx>,

src/librustc/infer/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ impl<'tcx, T> InferOk<'tcx, T> {
581581
pub fn into_value_registering_obligations(
582582
self,
583583
infcx: &InferCtxt<'_, '_, 'tcx>,
584-
fulfill_cx: &mut impl TraitEngine<'tcx>,
584+
fulfill_cx: &mut dyn TraitEngine<'tcx>,
585585
) -> T {
586586
let InferOk { value, obligations } = self;
587587
for obligation in obligations {

src/librustc/traits/select.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3243,11 +3243,14 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
32433243
trait_ref,
32443244
)?);
32453245

3246-
obligations.push(Obligation::new(
3247-
obligation.cause.clone(),
3248-
obligation.param_env,
3249-
ty::Predicate::ClosureKind(closure_def_id, substs, kind),
3250-
));
3246+
// FIXME: chalk
3247+
if !self.tcx().sess.opts.debugging_opts.chalk {
3248+
obligations.push(Obligation::new(
3249+
obligation.cause.clone(),
3250+
obligation.param_env,
3251+
ty::Predicate::ClosureKind(closure_def_id, substs, kind),
3252+
));
3253+
}
32513254

32523255
Ok(VtableClosureData {
32533256
closure_def_id,

src/librustc_traits/dropck_outlives.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rustc::hir::def_id::DefId;
22
use rustc::infer::canonical::{Canonical, QueryResponse};
33
use rustc::traits::query::dropck_outlives::{DropckOutlivesResult, DtorckConstraint};
44
use rustc::traits::query::{CanonicalTyGoal, NoSolution};
5-
use rustc::traits::{FulfillmentContext, Normalized, ObligationCause, TraitEngineExt};
5+
use rustc::traits::{TraitEngine, Normalized, ObligationCause, TraitEngineExt};
66
use rustc::ty::query::Providers;
77
use rustc::ty::subst::{Subst, Substs};
88
use rustc::ty::{self, ParamEnvAnd, Ty, TyCtxt};
@@ -78,7 +78,7 @@ fn dropck_outlives<'tcx>(
7878
// Set used to detect infinite recursion.
7979
let mut ty_set = FxHashSet::default();
8080

81-
let fulfill_cx = &mut FulfillmentContext::new();
81+
let mut fulfill_cx = TraitEngine::new(infcx.tcx);
8282

8383
let cause = ObligationCause::dummy();
8484
while let Some((ty, depth)) = ty_stack.pop() {
@@ -136,7 +136,11 @@ fn dropck_outlives<'tcx>(
136136

137137
debug!("dropck_outlives: result = {:#?}", result);
138138

139-
infcx.make_canonicalized_query_response(canonical_inference_vars, result, fulfill_cx)
139+
infcx.make_canonicalized_query_response(
140+
canonical_inference_vars,
141+
result,
142+
&mut *fulfill_cx
143+
)
140144
},
141145
)
142146
}

src/librustc_traits/type_op.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc::traits::query::type_op::prove_predicate::ProvePredicate;
1111
use rustc::traits::query::type_op::subtype::Subtype;
1212
use rustc::traits::query::{Fallible, NoSolution};
1313
use rustc::traits::{
14-
FulfillmentContext, Normalized, Obligation, ObligationCause, TraitEngine, TraitEngineExt,
14+
Normalized, Obligation, ObligationCause, TraitEngine, TraitEngineExt,
1515
};
1616
use rustc::ty::query::Providers;
1717
use rustc::ty::subst::{Kind, Subst, UserSelfTy, UserSubsts};
@@ -75,7 +75,7 @@ fn type_op_ascribe_user_type<'tcx>(
7575
struct AscribeUserTypeCx<'me, 'gcx: 'tcx, 'tcx: 'me> {
7676
infcx: &'me InferCtxt<'me, 'gcx, 'tcx>,
7777
param_env: ParamEnv<'tcx>,
78-
fulfill_cx: &'me mut FulfillmentContext<'tcx>,
78+
fulfill_cx: &'me mut dyn TraitEngine<'tcx>,
7979
}
8080

8181
impl AscribeUserTypeCx<'me, 'gcx, 'tcx> {
@@ -231,7 +231,7 @@ fn type_op_eq<'tcx>(
231231

232232
fn type_op_normalize<T>(
233233
infcx: &InferCtxt<'_, 'gcx, 'tcx>,
234-
fulfill_cx: &mut FulfillmentContext<'tcx>,
234+
fulfill_cx: &mut dyn TraitEngine<'tcx>,
235235
key: ParamEnvAnd<'tcx, Normalize<T>>,
236236
) -> Fallible<T>
237237
where

0 commit comments

Comments
 (0)