Skip to content

Commit 0ff7021

Browse files
Move FulfillmentContext out of InferCtxt
1 parent dc287a9 commit 0ff7021

File tree

9 files changed

+22
-24
lines changed

9 files changed

+22
-24
lines changed

src/librustc/middle/infer/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ pub struct InferCtxt<'a, 'tcx: 'a> {
8888

8989
pub parameter_environment: ty::ParameterEnvironment<'a, 'tcx>,
9090

91-
pub fulfillment_cx: RefCell<traits::FulfillmentContext<'tcx>>,
92-
9391
// the set of predicates on which errors have been reported, to
9492
// avoid reporting the same error twice.
9593
pub reported_trait_errors: RefCell<FnvHashSet<traits::TraitErrorKey<'tcx>>>,
@@ -366,7 +364,6 @@ pub fn new_infer_ctxt<'a, 'tcx>(tcx: &'a ty::ctxt<'tcx>,
366364
float_unification_table: RefCell::new(UnificationTable::new()),
367365
region_vars: RegionVarBindings::new(tcx),
368366
parameter_environment: param_env.unwrap_or(tcx.empty_parameter_environment()),
369-
fulfillment_cx: RefCell::new(traits::FulfillmentContext::new()),
370367
reported_trait_errors: RefCell::new(FnvHashSet()),
371368
normalize: false,
372369
err_count_on_creation: tcx.sess.err_count()
@@ -525,7 +522,7 @@ pub fn normalize_associated_type<'tcx,T>(tcx: &ty::ctxt<'tcx>, value: &T) -> T
525522
result,
526523
obligations);
527524

528-
let mut fulfill_cx = infcx.fulfillment_cx.borrow_mut();
525+
let mut fulfill_cx = traits::FulfillmentContext::new();
529526

530527
for obligation in obligations {
531528
fulfill_cx.register_predicate_obligation(&infcx, obligation);

src/librustc_passes/consts.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,9 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> {
249249
let ty = self.tcx.node_id_to_type(e.id);
250250
let infcx = infer::new_infer_ctxt(self.tcx, &self.tcx.tables, None);
251251
let cause = traits::ObligationCause::new(e.span, e.id, traits::SharedStatic);
252-
let mut fulfill_cx = infcx.fulfillment_cx.borrow_mut();
253-
fulfill_cx.register_builtin_bound(&infcx, ty, ty::BoundSync, cause);
254-
match fulfill_cx.select_all_or_error(&infcx) {
252+
let mut fulfillment_cx = traits::FulfillmentContext::new();
253+
fulfillment_cx.register_builtin_bound(&infcx, ty, ty::BoundSync, cause);
254+
match fulfillment_cx.select_all_or_error(&infcx) {
255255
Ok(()) => { },
256256
Err(ref errors) => {
257257
traits::report_fulfillment_errors(&infcx, errors);

src/librustc_trans/trans/common.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,7 @@ pub fn fulfill_obligation<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
11591159
// Currently, we use a fulfillment context to completely resolve
11601160
// all nested obligations. This is because they can inform the
11611161
// inference of the impl's type parameters.
1162-
let mut fulfill_cx = infcx.fulfillment_cx.borrow_mut();
1162+
let mut fulfill_cx = traits::FulfillmentContext::new();
11631163
let vtable = selection.map(|predicate| {
11641164
fulfill_cx.register_predicate_obligation(&infcx, predicate);
11651165
});
@@ -1188,7 +1188,7 @@ pub fn normalize_and_test_predicates<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
11881188
let tcx = ccx.tcx();
11891189
let infcx = infer::normalizing_infer_ctxt(tcx, &tcx.tables);
11901190
let mut selcx = traits::SelectionContext::new(&infcx);
1191-
let mut fulfill_cx = infcx.fulfillment_cx.borrow_mut();
1191+
let mut fulfill_cx = traits::FulfillmentContext::new();
11921192
let cause = traits::ObligationCause::dummy();
11931193
let traits::Normalized { value: predicates, obligations } =
11941194
traits::normalize(&mut selcx, cause.clone(), &predicates);

src/librustc_typeck/check/closure.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ fn deduce_expectations_from_obligations<'a,'tcx>(
134134
expected_vid: ty::TyVid)
135135
-> (Option<ty::FnSig<'tcx>>, Option<ty::ClosureKind>)
136136
{
137-
let fulfillment_cx = fcx.inh.infcx.fulfillment_cx.borrow();
137+
let fulfillment_cx = fcx.inh.fulfillment_cx.borrow();
138138
// Here `expected_ty` is known to be a type inference variable.
139139

140140
let expected_sig =

src/librustc_typeck/check/compare_method.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub fn compare_impl_method<'tcx>(tcx: &ty::ctxt<'tcx>,
4343
impl_trait_ref);
4444

4545
let mut infcx = infer::new_infer_ctxt(tcx, &tcx.tables, None);
46-
let mut fulfillment_cx = infcx.fulfillment_cx.borrow_mut();
46+
let mut fulfillment_cx = traits::FulfillmentContext::new();
4747

4848
let trait_to_impl_substs = &impl_trait_ref.substs;
4949

@@ -417,7 +417,7 @@ pub fn compare_const_impl<'tcx>(tcx: &ty::ctxt<'tcx>,
417417
impl_trait_ref);
418418

419419
let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, None);
420-
let mut fulfillment_cx = infcx.fulfillment_cx.borrow_mut();
420+
let mut fulfillment_cx = traits::FulfillmentContext::new();
421421

422422
// The below is for the most part highly similar to the procedure
423423
// for methods above. It is simpler in many respects, especially

src/librustc_typeck/check/dropck.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ fn ensure_drop_params_and_item_params_correspond<'tcx>(
8484

8585
let impl_param_env = ty::ParameterEnvironment::for_item(tcx, self_type_node_id);
8686
let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, Some(impl_param_env));
87+
let mut fulfillment_cx = traits::FulfillmentContext::new();
8788

8889
let named_type = tcx.lookup_item_type(self_type_did).ty;
8990
let named_type = named_type.subst(tcx, &infcx.parameter_environment.free_substs);
@@ -105,7 +106,7 @@ fn ensure_drop_params_and_item_params_correspond<'tcx>(
105106
return Err(());
106107
}
107108

108-
if let Err(ref errors) = infcx.fulfillment_cx.borrow_mut().select_all_or_error(&infcx) {
109+
if let Err(ref errors) = fulfillment_cx.select_all_or_error(&infcx) {
109110
// this could be reached when we get lazy normalization
110111
traits::report_fulfillment_errors(&infcx, errors);
111112
return Err(());

src/librustc_typeck/check/mod.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@ pub struct Inherited<'a, 'tcx: 'a> {
161161
infcx: infer::InferCtxt<'a, 'tcx>,
162162
locals: RefCell<NodeMap<Ty<'tcx>>>,
163163

164+
fulfillment_cx: RefCell<traits::FulfillmentContext<'tcx>>,
165+
164166
tables: &'a RefCell<ty::Tables<'tcx>>,
165167

166168
// When we process a call like `c()` where `c` is a closure type,
@@ -306,6 +308,7 @@ impl<'a, 'tcx> Inherited<'a, 'tcx> {
306308

307309
Inherited {
308310
infcx: infer::new_infer_ctxt(tcx, tables, Some(param_env)),
311+
fulfillment_cx: RefCell::new(traits::FulfillmentContext::new()),
309312
locals: RefCell::new(NodeMap()),
310313
tables: tables,
311314
deferred_call_resolutions: RefCell::new(DefIdMap()),
@@ -320,9 +323,8 @@ impl<'a, 'tcx> Inherited<'a, 'tcx> {
320323
-> T
321324
where T : TypeFoldable<'tcx>
322325
{
323-
let mut fulfillment_cx = self.infcx.fulfillment_cx.borrow_mut();
324326
assoc::normalize_associated_types_in(&self.infcx,
325-
&mut fulfillment_cx,
327+
&mut self.fulfillment_cx.borrow_mut(),
326328
span,
327329
body_id,
328330
value)
@@ -1370,7 +1372,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13701372
self.body_id,
13711373
traits::ObligationCauseCode::MiscObligation);
13721374
self.inh
1373-
.infcx
13741375
.fulfillment_cx
13751376
.borrow_mut()
13761377
.normalize_projection_type(self.infcx(),
@@ -1505,7 +1506,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15051506
builtin_bound: ty::BuiltinBound,
15061507
cause: traits::ObligationCause<'tcx>)
15071508
{
1508-
self.inh.infcx.fulfillment_cx.borrow_mut()
1509+
self.inh.fulfillment_cx.borrow_mut()
15091510
.register_builtin_bound(self.infcx(), ty, builtin_bound, cause);
15101511
}
15111512

@@ -1514,7 +1515,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15141515
{
15151516
debug!("register_predicate({:?})",
15161517
obligation);
1517-
self.inh.infcx.fulfillment_cx
1518+
self.inh.fulfillment_cx
15181519
.borrow_mut()
15191520
.register_predicate_obligation(self.infcx(), obligation);
15201521
}
@@ -1646,7 +1647,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
16461647
region: ty::Region,
16471648
cause: traits::ObligationCause<'tcx>)
16481649
{
1649-
let mut fulfillment_cx = self.inh.infcx.fulfillment_cx.borrow_mut();
1650+
let mut fulfillment_cx = self.inh.fulfillment_cx.borrow_mut();
16501651
fulfillment_cx.register_region_obligation(ty, region, cause);
16511652
}
16521653

@@ -2003,7 +2004,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
20032004

20042005
self.select_all_obligations_and_apply_defaults();
20052006

2006-
let mut fulfillment_cx = self.inh.infcx.fulfillment_cx.borrow_mut();
2007+
let mut fulfillment_cx = self.inh.fulfillment_cx.borrow_mut();
20072008
match fulfillment_cx.select_all_or_error(self.infcx()) {
20082009
Ok(()) => { }
20092010
Err(errors) => { report_fulfillment_errors(self.infcx(), &errors); }
@@ -2013,7 +2014,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
20132014
/// Select as many obligations as we can at present.
20142015
fn select_obligations_where_possible(&self) {
20152016
match
2016-
self.inh.infcx.fulfillment_cx
2017+
self.inh.fulfillment_cx
20172018
.borrow_mut()
20182019
.select_where_possible(self.infcx())
20192020
{

src/librustc_typeck/check/regionck.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,6 @@ impl<'a, 'tcx> Rcx<'a, 'tcx> {
353353
let region_obligations =
354354
self.fcx
355355
.inh
356-
.infcx
357356
.fulfillment_cx
358357
.borrow()
359358
.region_obligations(node_id)
@@ -369,7 +368,7 @@ impl<'a, 'tcx> Rcx<'a, 'tcx> {
369368

370369
// Processing the region obligations should not cause the list to grow further:
371370
assert_eq!(region_obligations.len(),
372-
self.fcx.inh.infcx.fulfillment_cx.borrow().region_obligations(node_id).len());
371+
self.fcx.inh.fulfillment_cx.borrow().region_obligations(node_id).len());
373372
}
374373

375374
fn code_to_origin(&self,

src/librustc_typeck/coherence/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> {
473473
}
474474
};
475475

476-
let mut fulfill_cx = infcx.fulfillment_cx.borrow_mut();
476+
let mut fulfill_cx = traits::FulfillmentContext::new();
477477

478478
// Register an obligation for `A: Trait<B>`.
479479
let cause = traits::ObligationCause::misc(span, impl_node_id);

0 commit comments

Comments
 (0)