diff options
Diffstat (limited to 'compiler/rustc_hir_typeck/src/inherited.rs')
-rw-r--r-- | compiler/rustc_hir_typeck/src/inherited.rs | 50 |
1 files changed, 7 insertions, 43 deletions
diff --git a/compiler/rustc_hir_typeck/src/inherited.rs b/compiler/rustc_hir_typeck/src/inherited.rs index 26020382d..4110b176b 100644 --- a/compiler/rustc_hir_typeck/src/inherited.rs +++ b/compiler/rustc_hir_typeck/src/inherited.rs @@ -4,7 +4,6 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_hir as hir; use rustc_hir::def_id::LocalDefId; use rustc_hir::HirIdMap; -use rustc_infer::infer; use rustc_infer::infer::{DefiningAnchor, InferCtxt, InferOk, TyCtxtInferExt}; use rustc_middle::ty::visit::TypeVisitableExt; use rustc_middle::ty::{self, Ty, TyCtxt}; @@ -58,8 +57,6 @@ pub struct Inherited<'tcx> { pub(super) deferred_generator_interiors: RefCell<Vec<(LocalDefId, hir::BodyId, Ty<'tcx>, hir::GeneratorKind)>>, - pub(super) body_id: Option<hir::BodyId>, - /// Whenever we introduce an adjustment from `!` into a type variable, /// we record that type variable here. This is later used to inform /// fallback. See the `fallback` module for details. @@ -75,48 +72,16 @@ impl<'tcx> Deref for Inherited<'tcx> { } } -/// A temporary returned by `Inherited::build(...)`. This is necessary -/// for multiple `InferCtxt` to share the same `typeck_results` -/// without using `Rc` or something similar. -pub struct InheritedBuilder<'tcx> { - infcx: infer::InferCtxtBuilder<'tcx>, - def_id: LocalDefId, - typeck_results: RefCell<ty::TypeckResults<'tcx>>, -} - impl<'tcx> Inherited<'tcx> { - pub fn build(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> InheritedBuilder<'tcx> { + pub fn new(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Self { let hir_owner = tcx.hir().local_def_id_to_hir_id(def_id).owner; - InheritedBuilder { - infcx: tcx - .infer_ctxt() - .ignoring_regions() - .with_opaque_type_inference(DefiningAnchor::Bind(hir_owner.def_id)), - def_id, - typeck_results: RefCell::new(ty::TypeckResults::new(hir_owner)), - } - } -} - -impl<'tcx> InheritedBuilder<'tcx> { - pub fn enter<F, R>(mut self, f: F) -> R - where - F: FnOnce(&Inherited<'tcx>) -> R, - { - let def_id = self.def_id; - f(&Inherited::new(self.infcx.build(), def_id, self.typeck_results)) - } -} - -impl<'tcx> Inherited<'tcx> { - fn new( - infcx: InferCtxt<'tcx>, - def_id: LocalDefId, - typeck_results: RefCell<ty::TypeckResults<'tcx>>, - ) -> Self { - let tcx = infcx.tcx; - let body_id = tcx.hir().maybe_body_owned_by(def_id); + let infcx = tcx + .infer_ctxt() + .ignoring_regions() + .with_opaque_type_inference(DefiningAnchor::Bind(hir_owner.def_id)) + .build(); + let typeck_results = RefCell::new(ty::TypeckResults::new(hir_owner)); Inherited { typeck_results, @@ -130,7 +95,6 @@ impl<'tcx> Inherited<'tcx> { deferred_asm_checks: RefCell::new(Vec::new()), deferred_generator_interiors: RefCell::new(Vec::new()), diverging_type_vars: RefCell::new(Default::default()), - body_id, infer_var_info: RefCell::new(Default::default()), } } |