Moved another struct and used pub(super) to be explicit

This commit is contained in:
Nicholas-Baron 2020-09-19 01:09:45 -07:00
parent bfe5bc9cb9
commit 6fd80e35e0
2 changed files with 36 additions and 33 deletions

View File

@ -87,6 +87,7 @@
use crate::astconv::{ use crate::astconv::{
AstConv, ExplicitLateBound, GenericArgCountMismatch, GenericArgCountResult, PathSeg, AstConv, ExplicitLateBound, GenericArgCountMismatch, GenericArgCountResult, PathSeg,
}; };
use crate::check::util::MaybeInProgressTables;
use rustc_ast as ast; use rustc_ast as ast;
use rustc_ast::util::parser::ExprPrecedence; use rustc_ast::util::parser::ExprPrecedence;
use rustc_attr as attr; use rustc_attr as attr;
@ -141,7 +142,7 @@
self, ObligationCause, ObligationCauseCode, TraitEngine, TraitEngineExt, self, ObligationCause, ObligationCauseCode, TraitEngine, TraitEngineExt,
}; };
use std::cell::{Cell, Ref, RefCell, RefMut}; use std::cell::{Cell, RefCell};
use std::cmp; use std::cmp;
use std::collections::hash_map::Entry; use std::collections::hash_map::Entry;
use std::iter; use std::iter;
@ -177,32 +178,6 @@ pub struct LocalTy<'tcx> {
revealed_ty: Ty<'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<ty::TypeckResults<'tcx>>>,
}
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: /// Closures defined within the function. For example:
/// ///
/// fn foo() { /// fn foo() {

View File

@ -1,26 +1,54 @@
use rustc_hir::def_id::{CrateNum, LocalDefId, LOCAL_CRATE}; use rustc_hir::def_id::{CrateNum, LocalDefId, LOCAL_CRATE};
use std::cell::{Ref, RefCell, RefMut};
use super::wfcheck; use super::wfcheck;
use crate::check::CheckItemTypesVisitor; 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<ty::TypeckResults<'tcx>>>,
}
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 }); 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); 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); 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); 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); debug_assert!(crate_num == LOCAL_CRATE);
tcx.par_body_owners(|body_owner_def_id| { tcx.par_body_owners(|body_owner_def_id| {
tcx.ensure().typeck(body_owner_def_id); tcx.ensure().typeck(body_owner_def_id);