diff --git a/src/librustc/middle/infer/mod.rs b/src/librustc/middle/infer/mod.rs index 15e368812f2..26ea5454693 100644 --- a/src/librustc/middle/infer/mod.rs +++ b/src/librustc/middle/infer/mod.rs @@ -88,8 +88,6 @@ pub struct InferCtxt<'a, 'tcx: 'a> { pub parameter_environment: ty::ParameterEnvironment<'a, 'tcx>, - pub fulfillment_cx: RefCell>, - // the set of predicates on which errors have been reported, to // avoid reporting the same error twice. pub reported_trait_errors: RefCell>>, @@ -366,7 +364,6 @@ pub fn new_infer_ctxt<'a, 'tcx>(tcx: &'a ty::ctxt<'tcx>, float_unification_table: RefCell::new(UnificationTable::new()), region_vars: RegionVarBindings::new(tcx), parameter_environment: param_env.unwrap_or(tcx.empty_parameter_environment()), - fulfillment_cx: RefCell::new(traits::FulfillmentContext::new()), reported_trait_errors: RefCell::new(FnvHashSet()), normalize: false, 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 result, obligations); - let mut fulfill_cx = infcx.fulfillment_cx.borrow_mut(); + let mut fulfill_cx = traits::FulfillmentContext::new(); for obligation in obligations { fulfill_cx.register_predicate_obligation(&infcx, obligation); diff --git a/src/librustc_passes/consts.rs b/src/librustc_passes/consts.rs index 60cc658eeca..27b293d9416 100644 --- a/src/librustc_passes/consts.rs +++ b/src/librustc_passes/consts.rs @@ -249,9 +249,9 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> { let ty = self.tcx.node_id_to_type(e.id); let infcx = infer::new_infer_ctxt(self.tcx, &self.tcx.tables, None); let cause = traits::ObligationCause::new(e.span, e.id, traits::SharedStatic); - let mut fulfill_cx = infcx.fulfillment_cx.borrow_mut(); - fulfill_cx.register_builtin_bound(&infcx, ty, ty::BoundSync, cause); - match fulfill_cx.select_all_or_error(&infcx) { + let mut fulfillment_cx = traits::FulfillmentContext::new(); + fulfillment_cx.register_builtin_bound(&infcx, ty, ty::BoundSync, cause); + match fulfillment_cx.select_all_or_error(&infcx) { Ok(()) => { }, Err(ref errors) => { traits::report_fulfillment_errors(&infcx, errors); diff --git a/src/librustc_trans/trans/common.rs b/src/librustc_trans/trans/common.rs index 1269c266c7c..eb54527b373 100644 --- a/src/librustc_trans/trans/common.rs +++ b/src/librustc_trans/trans/common.rs @@ -1159,7 +1159,7 @@ pub fn fulfill_obligation<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, // Currently, we use a fulfillment context to completely resolve // all nested obligations. This is because they can inform the // inference of the impl's type parameters. - let mut fulfill_cx = infcx.fulfillment_cx.borrow_mut(); + let mut fulfill_cx = traits::FulfillmentContext::new(); let vtable = selection.map(|predicate| { fulfill_cx.register_predicate_obligation(&infcx, predicate); }); @@ -1188,7 +1188,7 @@ pub fn normalize_and_test_predicates<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, let tcx = ccx.tcx(); let infcx = infer::normalizing_infer_ctxt(tcx, &tcx.tables); let mut selcx = traits::SelectionContext::new(&infcx); - let mut fulfill_cx = infcx.fulfillment_cx.borrow_mut(); + let mut fulfill_cx = traits::FulfillmentContext::new(); let cause = traits::ObligationCause::dummy(); let traits::Normalized { value: predicates, obligations } = traits::normalize(&mut selcx, cause.clone(), &predicates); diff --git a/src/librustc_typeck/check/closure.rs b/src/librustc_typeck/check/closure.rs index 3b7cb2bd4b4..64e7dd5c4a3 100644 --- a/src/librustc_typeck/check/closure.rs +++ b/src/librustc_typeck/check/closure.rs @@ -134,7 +134,7 @@ fn deduce_expectations_from_obligations<'a,'tcx>( expected_vid: ty::TyVid) -> (Option>, Option) { - let fulfillment_cx = fcx.inh.infcx.fulfillment_cx.borrow(); + let fulfillment_cx = fcx.inh.fulfillment_cx.borrow(); // Here `expected_ty` is known to be a type inference variable. let expected_sig = diff --git a/src/librustc_typeck/check/compare_method.rs b/src/librustc_typeck/check/compare_method.rs index d5f24220189..d674fa145dc 100644 --- a/src/librustc_typeck/check/compare_method.rs +++ b/src/librustc_typeck/check/compare_method.rs @@ -43,7 +43,7 @@ pub fn compare_impl_method<'tcx>(tcx: &ty::ctxt<'tcx>, impl_trait_ref); let mut infcx = infer::new_infer_ctxt(tcx, &tcx.tables, None); - let mut fulfillment_cx = infcx.fulfillment_cx.borrow_mut(); + let mut fulfillment_cx = traits::FulfillmentContext::new(); let trait_to_impl_substs = &impl_trait_ref.substs; @@ -417,7 +417,7 @@ pub fn compare_const_impl<'tcx>(tcx: &ty::ctxt<'tcx>, impl_trait_ref); let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, None); - let mut fulfillment_cx = infcx.fulfillment_cx.borrow_mut(); + let mut fulfillment_cx = traits::FulfillmentContext::new(); // The below is for the most part highly similar to the procedure // for methods above. It is simpler in many respects, especially diff --git a/src/librustc_typeck/check/dropck.rs b/src/librustc_typeck/check/dropck.rs index deda0b818ee..9d396533757 100644 --- a/src/librustc_typeck/check/dropck.rs +++ b/src/librustc_typeck/check/dropck.rs @@ -84,6 +84,7 @@ fn ensure_drop_params_and_item_params_correspond<'tcx>( let impl_param_env = ty::ParameterEnvironment::for_item(tcx, self_type_node_id); let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, Some(impl_param_env)); + let mut fulfillment_cx = traits::FulfillmentContext::new(); let named_type = tcx.lookup_item_type(self_type_did).ty; 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>( return Err(()); } - if let Err(ref errors) = infcx.fulfillment_cx.borrow_mut().select_all_or_error(&infcx) { + if let Err(ref errors) = fulfillment_cx.select_all_or_error(&infcx) { // this could be reached when we get lazy normalization traits::report_fulfillment_errors(&infcx, errors); return Err(()); diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index a476f9e1a80..b96bac4adf8 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -161,6 +161,8 @@ pub struct Inherited<'a, 'tcx: 'a> { infcx: infer::InferCtxt<'a, 'tcx>, locals: RefCell>>, + fulfillment_cx: RefCell>, + tables: &'a RefCell>, // When we process a call like `c()` where `c` is a closure type, @@ -306,6 +308,7 @@ impl<'a, 'tcx> Inherited<'a, 'tcx> { Inherited { infcx: infer::new_infer_ctxt(tcx, tables, Some(param_env)), + fulfillment_cx: RefCell::new(traits::FulfillmentContext::new()), locals: RefCell::new(NodeMap()), tables: tables, deferred_call_resolutions: RefCell::new(DefIdMap()), @@ -320,9 +323,8 @@ impl<'a, 'tcx> Inherited<'a, 'tcx> { -> T where T : TypeFoldable<'tcx> { - let mut fulfillment_cx = self.infcx.fulfillment_cx.borrow_mut(); assoc::normalize_associated_types_in(&self.infcx, - &mut fulfillment_cx, + &mut self.fulfillment_cx.borrow_mut(), span, body_id, value) @@ -1370,7 +1372,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.body_id, traits::ObligationCauseCode::MiscObligation); self.inh - .infcx .fulfillment_cx .borrow_mut() .normalize_projection_type(self.infcx(), @@ -1505,7 +1506,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { builtin_bound: ty::BuiltinBound, cause: traits::ObligationCause<'tcx>) { - self.inh.infcx.fulfillment_cx.borrow_mut() + self.inh.fulfillment_cx.borrow_mut() .register_builtin_bound(self.infcx(), ty, builtin_bound, cause); } @@ -1514,7 +1515,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { { debug!("register_predicate({:?})", obligation); - self.inh.infcx.fulfillment_cx + self.inh.fulfillment_cx .borrow_mut() .register_predicate_obligation(self.infcx(), obligation); } @@ -1646,7 +1647,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { region: ty::Region, cause: traits::ObligationCause<'tcx>) { - let mut fulfillment_cx = self.inh.infcx.fulfillment_cx.borrow_mut(); + let mut fulfillment_cx = self.inh.fulfillment_cx.borrow_mut(); fulfillment_cx.register_region_obligation(ty, region, cause); } @@ -2003,7 +2004,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.select_all_obligations_and_apply_defaults(); - let mut fulfillment_cx = self.inh.infcx.fulfillment_cx.borrow_mut(); + let mut fulfillment_cx = self.inh.fulfillment_cx.borrow_mut(); match fulfillment_cx.select_all_or_error(self.infcx()) { Ok(()) => { } Err(errors) => { report_fulfillment_errors(self.infcx(), &errors); } @@ -2013,7 +2014,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// Select as many obligations as we can at present. fn select_obligations_where_possible(&self) { match - self.inh.infcx.fulfillment_cx + self.inh.fulfillment_cx .borrow_mut() .select_where_possible(self.infcx()) { diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index 56b02412c31..1acda6b2375 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -353,7 +353,6 @@ impl<'a, 'tcx> Rcx<'a, 'tcx> { let region_obligations = self.fcx .inh - .infcx .fulfillment_cx .borrow() .region_obligations(node_id) @@ -369,7 +368,7 @@ impl<'a, 'tcx> Rcx<'a, 'tcx> { // Processing the region obligations should not cause the list to grow further: assert_eq!(region_obligations.len(), - self.fcx.inh.infcx.fulfillment_cx.borrow().region_obligations(node_id).len()); + self.fcx.inh.fulfillment_cx.borrow().region_obligations(node_id).len()); } fn code_to_origin(&self, diff --git a/src/librustc_typeck/coherence/mod.rs b/src/librustc_typeck/coherence/mod.rs index 7e63fd47d61..2dfbaab2844 100644 --- a/src/librustc_typeck/coherence/mod.rs +++ b/src/librustc_typeck/coherence/mod.rs @@ -473,7 +473,7 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> { } }; - let mut fulfill_cx = infcx.fulfillment_cx.borrow_mut(); + let mut fulfill_cx = traits::FulfillmentContext::new(); // Register an obligation for `A: Trait`. let cause = traits::ObligationCause::misc(span, impl_node_id);