diff --git a/compiler/rustc_typeck/src/check/mod.rs b/compiler/rustc_typeck/src/check/mod.rs index 1b542818b6f..560248480cf 100644 --- a/compiler/rustc_typeck/src/check/mod.rs +++ b/compiler/rustc_typeck/src/check/mod.rs @@ -87,6 +87,7 @@ use crate::astconv::{ AstConv, ExplicitLateBound, GenericArgCountMismatch, GenericArgCountResult, PathSeg, }; +use crate::check::util::MaybeInProgressTables; use rustc_ast as ast; use rustc_ast::util::parser::ExprPrecedence; use rustc_attr as attr; @@ -141,7 +142,7 @@ self, ObligationCause, ObligationCauseCode, TraitEngine, TraitEngineExt, }; -use std::cell::{Cell, Ref, RefCell, RefMut}; +use std::cell::{Cell, RefCell}; use std::cmp; use std::collections::hash_map::Entry; use std::iter; @@ -177,32 +178,6 @@ pub struct LocalTy<'tcx> { revealed_ty: Ty<'tcx>, } -/// A wrapper for `InferCtxt`'s `in_progress_typeck_results` field. -#[derive(Copy, Clone)] -struct MaybeInProgressTables<'a, 'tcx> { - maybe_typeck_results: Option<&'a RefCell>>, -} - -impl<'a, 'tcx> MaybeInProgressTables<'a, 'tcx> { - fn borrow(self) -> Ref<'a, ty::TypeckResults<'tcx>> { - match self.maybe_typeck_results { - Some(typeck_results) => typeck_results.borrow(), - None => bug!( - "MaybeInProgressTables: inh/fcx.typeck_results.borrow() with no typeck results" - ), - } - } - - fn borrow_mut(self) -> RefMut<'a, ty::TypeckResults<'tcx>> { - match self.maybe_typeck_results { - Some(typeck_results) => typeck_results.borrow_mut(), - None => bug!( - "MaybeInProgressTables: inh/fcx.typeck_results.borrow_mut() with no typeck results" - ), - } - } -} - /// Closures defined within the function. For example: /// /// fn foo() { diff --git a/compiler/rustc_typeck/src/check/util.rs b/compiler/rustc_typeck/src/check/util.rs index 973c9a2a26a..9a948c949ec 100644 --- a/compiler/rustc_typeck/src/check/util.rs +++ b/compiler/rustc_typeck/src/check/util.rs @@ -1,26 +1,54 @@ use rustc_hir::def_id::{CrateNum, LocalDefId, LOCAL_CRATE}; +use std::cell::{Ref, RefCell, RefMut}; + use super::wfcheck; use crate::check::CheckItemTypesVisitor; -use crate::TyCtxt; +use crate::{ty, TyCtxt}; -pub fn check_mod_item_types(tcx: TyCtxt<'_>, module_def_id: LocalDefId) { +/// A wrapper for `InferCtxt`'s `in_progress_typeck_results` field. +#[derive(Copy, Clone)] +pub(super) struct MaybeInProgressTables<'a, 'tcx> { + pub(super) maybe_typeck_results: Option<&'a RefCell>>, +} + +impl<'a, 'tcx> MaybeInProgressTables<'a, 'tcx> { + pub(super) fn borrow(self) -> Ref<'a, ty::TypeckResults<'tcx>> { + match self.maybe_typeck_results { + Some(typeck_results) => typeck_results.borrow(), + None => bug!( + "MaybeInProgressTables: inh/fcx.typeck_results.borrow() with no typeck results" + ), + } + } + + pub(super) fn borrow_mut(self) -> RefMut<'a, ty::TypeckResults<'tcx>> { + match self.maybe_typeck_results { + Some(typeck_results) => typeck_results.borrow_mut(), + None => bug!( + "MaybeInProgressTables: inh/fcx.typeck_results.borrow_mut() with no typeck results" + ), + } + } +} + +pub(super) fn check_mod_item_types(tcx: TyCtxt<'_>, module_def_id: LocalDefId) { tcx.hir().visit_item_likes_in_module(module_def_id, &mut CheckItemTypesVisitor { tcx }); } -pub fn check_item_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) { +pub(super) fn check_item_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) { wfcheck::check_item_well_formed(tcx, def_id); } -pub fn check_trait_item_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) { +pub(super) fn check_trait_item_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) { wfcheck::check_trait_item(tcx, def_id); } -pub fn check_impl_item_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) { +pub(super) fn check_impl_item_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) { wfcheck::check_impl_item(tcx, def_id); } -pub fn typeck_item_bodies(tcx: TyCtxt<'_>, crate_num: CrateNum) { +pub(super) fn typeck_item_bodies(tcx: TyCtxt<'_>, crate_num: CrateNum) { debug_assert!(crate_num == LOCAL_CRATE); tcx.par_body_owners(|body_owner_def_id| { tcx.ensure().typeck(body_owner_def_id);