|
1 | 1 | use rustc_hir::def_id::{CrateNum, LocalDefId, LOCAL_CRATE};
|
2 | 2 |
|
| 3 | +use std::cell::{Ref, RefCell, RefMut}; |
| 4 | + |
3 | 5 | use super::wfcheck;
|
4 | 6 | use crate::check::CheckItemTypesVisitor;
|
5 |
| -use crate::TyCtxt; |
| 7 | +use crate::{ty, TyCtxt}; |
| 8 | + |
| 9 | +/// A wrapper for `InferCtxt`'s `in_progress_typeck_results` field. |
| 10 | +#[derive(Copy, Clone)] |
| 11 | +pub(super) struct MaybeInProgressTables<'a, 'tcx> { |
| 12 | + pub(super) maybe_typeck_results: Option<&'a RefCell<ty::TypeckResults<'tcx>>>, |
| 13 | +} |
| 14 | + |
| 15 | +impl<'a, 'tcx> MaybeInProgressTables<'a, 'tcx> { |
| 16 | + pub(super) fn borrow(self) -> Ref<'a, ty::TypeckResults<'tcx>> { |
| 17 | + match self.maybe_typeck_results { |
| 18 | + Some(typeck_results) => typeck_results.borrow(), |
| 19 | + None => bug!( |
| 20 | + "MaybeInProgressTables: inh/fcx.typeck_results.borrow() with no typeck results" |
| 21 | + ), |
| 22 | + } |
| 23 | + } |
| 24 | + |
| 25 | + pub(super) fn borrow_mut(self) -> RefMut<'a, ty::TypeckResults<'tcx>> { |
| 26 | + match self.maybe_typeck_results { |
| 27 | + Some(typeck_results) => typeck_results.borrow_mut(), |
| 28 | + None => bug!( |
| 29 | + "MaybeInProgressTables: inh/fcx.typeck_results.borrow_mut() with no typeck results" |
| 30 | + ), |
| 31 | + } |
| 32 | + } |
| 33 | +} |
6 | 34 |
|
7 |
| -pub fn check_mod_item_types(tcx: TyCtxt<'_>, module_def_id: LocalDefId) { |
| 35 | +pub(super) fn check_mod_item_types(tcx: TyCtxt<'_>, module_def_id: LocalDefId) { |
8 | 36 | tcx.hir().visit_item_likes_in_module(module_def_id, &mut CheckItemTypesVisitor { tcx });
|
9 | 37 | }
|
10 | 38 |
|
11 |
| -pub fn check_item_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) { |
| 39 | +pub(super) fn check_item_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) { |
12 | 40 | wfcheck::check_item_well_formed(tcx, def_id);
|
13 | 41 | }
|
14 | 42 |
|
15 |
| -pub fn check_trait_item_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) { |
| 43 | +pub(super) fn check_trait_item_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) { |
16 | 44 | wfcheck::check_trait_item(tcx, def_id);
|
17 | 45 | }
|
18 | 46 |
|
19 |
| -pub fn check_impl_item_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) { |
| 47 | +pub(super) fn check_impl_item_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) { |
20 | 48 | wfcheck::check_impl_item(tcx, def_id);
|
21 | 49 | }
|
22 | 50 |
|
23 |
| -pub fn typeck_item_bodies(tcx: TyCtxt<'_>, crate_num: CrateNum) { |
| 51 | +pub(super) fn typeck_item_bodies(tcx: TyCtxt<'_>, crate_num: CrateNum) { |
24 | 52 | debug_assert!(crate_num == LOCAL_CRATE);
|
25 | 53 | tcx.par_body_owners(|body_owner_def_id| {
|
26 | 54 | tcx.ensure().typeck(body_owner_def_id);
|
|
0 commit comments