diff options
3 files changed, 23 insertions, 55 deletions
diff --git a/src/librustc_mir/borrow_check/nll/type_check/input_output.rs b/src/librustc_mir/borrow_check/nll/type_check/input_output.rs index afc21948e40..8144641a5ef 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/input_output.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/input_output.rs @@ -76,12 +76,13 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { "equate_inputs_and_outputs: normalized output_ty={:?}", output_ty ); + let param_env = self.param_env; let mir_output_ty = mir.local_decls[RETURN_PLACE].ty; let anon_type_map = self.fully_perform_op( Locations::All, CustomTypeOp::new( - |cx| { + |infcx| { let mut obligations = ObligationAccumulator::default(); let dummy_body_id = ObligationCause::dummy().body_id; @@ -89,7 +90,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { obligations.add(infcx.instantiate_anon_types( mir_def_id, dummy_body_id, - cx.param_env, + param_env, &output_ty, )); debug!( @@ -107,7 +108,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { ); obligations.add( infcx - .at(&ObligationCause::dummy(), cx.param_env) + .at(&ObligationCause::dummy(), param_env) .eq(output_ty, mir_output_ty)?, ); @@ -115,7 +116,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { let anon_defn_ty = tcx.type_of(anon_def_id); let anon_defn_ty = anon_defn_ty.subst(tcx, anon_decl.substs); let anon_defn_ty = renumber::renumber_regions( - cx.infcx, + infcx, TyContext::Location(Location::START), &anon_defn_ty, ); @@ -126,7 +127,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { debug!("equate_inputs_and_outputs: anon_defn_ty={:?}", anon_defn_ty); obligations.add( infcx - .at(&ObligationCause::dummy(), cx.param_env) + .at(&ObligationCause::dummy(), param_env) .eq(anon_decl.concrete_ty, anon_defn_ty)?, ); } diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs index 959532fff8d..f81b56de248 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs @@ -783,23 +783,24 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { info!("fully_perform_op_and_get_region_constraint_data({:?})", op,); } - let mut fulfill_cx = TraitEngine::new(self.infcx.tcx); + let infcx = self.infcx; + let mut fulfill_cx = TraitEngine::new(infcx.tcx); let dummy_body_id = ObligationCause::dummy().body_id; - let InferOk { value, obligations } = self.infcx.commit_if_ok(|_| op.perform(self))?; + let InferOk { value, obligations } = infcx.commit_if_ok(|_| op.perform(infcx))?; debug_assert!(obligations.iter().all(|o| o.cause.body_id == dummy_body_id)); - fulfill_cx.register_predicate_obligations(self.infcx, obligations); - if let Err(e) = fulfill_cx.select_all_or_error(self.infcx) { + fulfill_cx.register_predicate_obligations(infcx, obligations); + if let Err(e) = fulfill_cx.select_all_or_error(infcx) { span_mirbug!(self, "", "errors selecting obligation: {:?}", e); } - self.infcx.process_registered_region_obligations( + infcx.process_registered_region_obligations( self.region_bound_pairs, self.implicit_region_bound, self.param_env, dummy_body_id, ); - let data = self.infcx.take_and_reset_region_constraints(); + let data = infcx.take_and_reset_region_constraints(); if data.is_empty() { Ok((value, None)) } else { diff --git a/src/librustc_mir/borrow_check/nll/type_check/type_op/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/type_op/mod.rs index cf4464905c0..127841bec7c 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/type_op/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/type_op/mod.rs @@ -8,7 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use borrow_check::nll::type_check::TypeChecker; use rustc::infer::{InferCtxt, InferOk, InferResult}; use rustc::traits::query::NoSolution; use rustc::traits::{Normalized, Obligation, ObligationCause, PredicateObligation}; @@ -24,11 +23,7 @@ pub(super) trait TypeOp<'gcx, 'tcx>: Sized + fmt::Debug { /// produce the output, else returns `Err(self)` back. fn trivial_noop(self) -> Result<Self::Output, Self>; - /// Produce a description of the operation for the debug logs. - fn perform( - self, - type_checker: &mut TypeChecker<'_, 'gcx, 'tcx>, - ) -> InferResult<'tcx, Self::Output>; + fn perform(self, infcx: &InferCtxt<'_, 'gcx, 'tcx>) -> InferResult<'tcx, Self::Output>; } pub(super) struct CustomTypeOp<F, G> { @@ -39,7 +34,7 @@ pub(super) struct CustomTypeOp<F, G> { impl<F, G> CustomTypeOp<F, G> { pub(super) fn new<'gcx, 'tcx, R>(closure: F, description: G) -> Self where - F: FnOnce(&mut TypeChecker<'_, 'gcx, 'tcx>) -> InferResult<'tcx, R>, + F: FnOnce(&InferCtxt<'_, 'gcx, 'tcx>) -> InferResult<'tcx, R>, G: Fn() -> String, { CustomTypeOp { closure, description } @@ -48,7 +43,7 @@ impl<F, G> CustomTypeOp<F, G> { impl<'gcx, 'tcx, F, R, G> TypeOp<'gcx, 'tcx> for CustomTypeOp<F, G> where - F: FnOnce(&mut TypeChecker<'_, 'gcx, 'tcx>) -> InferResult<'tcx, R>, + F: FnOnce(&InferCtxt<'_, 'gcx, 'tcx>) -> InferResult<'tcx, R>, G: Fn() -> String, { type Output = R; @@ -57,8 +52,8 @@ where Err(self) } - fn perform(self, type_checker: &mut TypeChecker<'_, 'gcx, 'tcx>) -> InferResult<'tcx, R> { - (self.closure)(type_checker) + fn perform(self, infcx: &InferCtxt<'_, 'gcx, 'tcx>) -> InferResult<'tcx, R> { + (self.closure)(infcx) } } @@ -71,35 +66,6 @@ where } } -pub(super) trait InfcxTypeOp<'gcx, 'tcx>: Sized + fmt::Debug { - type Output; - - /// Micro-optimization: returns `Ok(x)` if we can trivially - /// produce the output, else returns `Err(self)` back. - fn trivial_noop(self) -> Result<Self::Output, Self>; - - /// Produce a description of the operation for the debug logs. - fn perform(self, infcx: &InferCtxt<'_, 'gcx, 'tcx>) -> InferResult<'tcx, Self::Output>; -} - -impl<'gcx, 'tcx, OP> TypeOp<'gcx, 'tcx> for OP -where - OP: InfcxTypeOp<'gcx, 'tcx>, -{ - type Output = OP::Output; - - fn trivial_noop(self) -> Result<Self::Output, Self> { - InfcxTypeOp::trivial_noop(self) - } - - fn perform( - self, - type_checker: &mut TypeChecker<'_, 'gcx, 'tcx>, - ) -> InferResult<'tcx, OP::Output> { - InfcxTypeOp::perform(self, type_checker.infcx) - } -} - #[derive(Debug)] pub(super) struct Subtype<'tcx> { param_env: ParamEnv<'tcx>, @@ -117,7 +83,7 @@ impl<'tcx> Subtype<'tcx> { } } -impl<'gcx, 'tcx> InfcxTypeOp<'gcx, 'tcx> for Subtype<'tcx> { +impl<'gcx, 'tcx> TypeOp<'gcx, 'tcx> for Subtype<'tcx> { type Output = (); fn trivial_noop(self) -> Result<Self::Output, Self> { @@ -148,7 +114,7 @@ impl<'tcx> Eq<'tcx> { } } -impl<'gcx, 'tcx> InfcxTypeOp<'gcx, 'tcx> for Eq<'tcx> { +impl<'gcx, 'tcx> TypeOp<'gcx, 'tcx> for Eq<'tcx> { type Output = (); fn trivial_noop(self) -> Result<Self::Output, Self> { @@ -185,7 +151,7 @@ impl<'tcx> ProvePredicates<'tcx> { } } -impl<'gcx, 'tcx> InfcxTypeOp<'gcx, 'tcx> for ProvePredicates<'tcx> { +impl<'gcx, 'tcx> TypeOp<'gcx, 'tcx> for ProvePredicates<'tcx> { type Output = (); fn trivial_noop(self) -> Result<Self::Output, Self> { @@ -219,7 +185,7 @@ where } } -impl<'gcx, 'tcx, T> InfcxTypeOp<'gcx, 'tcx> for Normalize<'tcx, T> +impl<'gcx, 'tcx, T> TypeOp<'gcx, 'tcx> for Normalize<'tcx, T> where T: fmt::Debug + TypeFoldable<'tcx>, { @@ -259,7 +225,7 @@ impl<'tcx> DropckOutlives<'tcx> { } } -impl<'gcx, 'tcx> InfcxTypeOp<'gcx, 'tcx> for DropckOutlives<'tcx> { +impl<'gcx, 'tcx> TypeOp<'gcx, 'tcx> for DropckOutlives<'tcx> { type Output = Vec<Kind<'tcx>>; fn trivial_noop(self) -> Result<Self::Output, Self> { |
