Skip to content

Commit 6fd80e3

Browse files
Moved another struct and used pub(super) to be explicit
1 parent bfe5bc9 commit 6fd80e3

File tree

2 files changed

+36
-33
lines changed

2 files changed

+36
-33
lines changed

compiler/rustc_typeck/src/check/mod.rs

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ pub mod writeback;
8787
use crate::astconv::{
8888
AstConv, ExplicitLateBound, GenericArgCountMismatch, GenericArgCountResult, PathSeg,
8989
};
90+
use crate::check::util::MaybeInProgressTables;
9091
use rustc_ast as ast;
9192
use rustc_ast::util::parser::ExprPrecedence;
9293
use rustc_attr as attr;
@@ -141,7 +142,7 @@ use rustc_trait_selection::traits::{
141142
self, ObligationCause, ObligationCauseCode, TraitEngine, TraitEngineExt,
142143
};
143144

144-
use std::cell::{Cell, Ref, RefCell, RefMut};
145+
use std::cell::{Cell, RefCell};
145146
use std::cmp;
146147
use std::collections::hash_map::Entry;
147148
use std::iter;
@@ -177,32 +178,6 @@ pub struct LocalTy<'tcx> {
177178
revealed_ty: Ty<'tcx>,
178179
}
179180

180-
/// A wrapper for `InferCtxt`'s `in_progress_typeck_results` field.
181-
#[derive(Copy, Clone)]
182-
struct MaybeInProgressTables<'a, 'tcx> {
183-
maybe_typeck_results: Option<&'a RefCell<ty::TypeckResults<'tcx>>>,
184-
}
185-
186-
impl<'a, 'tcx> MaybeInProgressTables<'a, 'tcx> {
187-
fn borrow(self) -> Ref<'a, ty::TypeckResults<'tcx>> {
188-
match self.maybe_typeck_results {
189-
Some(typeck_results) => typeck_results.borrow(),
190-
None => bug!(
191-
"MaybeInProgressTables: inh/fcx.typeck_results.borrow() with no typeck results"
192-
),
193-
}
194-
}
195-
196-
fn borrow_mut(self) -> RefMut<'a, ty::TypeckResults<'tcx>> {
197-
match self.maybe_typeck_results {
198-
Some(typeck_results) => typeck_results.borrow_mut(),
199-
None => bug!(
200-
"MaybeInProgressTables: inh/fcx.typeck_results.borrow_mut() with no typeck results"
201-
),
202-
}
203-
}
204-
}
205-
206181
/// Closures defined within the function. For example:
207182
///
208183
/// fn foo() {

compiler/rustc_typeck/src/check/util.rs

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,54 @@
11
use rustc_hir::def_id::{CrateNum, LocalDefId, LOCAL_CRATE};
22

3+
use std::cell::{Ref, RefCell, RefMut};
4+
35
use super::wfcheck;
46
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+
}
634

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) {
836
tcx.hir().visit_item_likes_in_module(module_def_id, &mut CheckItemTypesVisitor { tcx });
937
}
1038

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) {
1240
wfcheck::check_item_well_formed(tcx, def_id);
1341
}
1442

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) {
1644
wfcheck::check_trait_item(tcx, def_id);
1745
}
1846

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) {
2048
wfcheck::check_impl_item(tcx, def_id);
2149
}
2250

23-
pub fn typeck_item_bodies(tcx: TyCtxt<'_>, crate_num: CrateNum) {
51+
pub(super) fn typeck_item_bodies(tcx: TyCtxt<'_>, crate_num: CrateNum) {
2452
debug_assert!(crate_num == LOCAL_CRATE);
2553
tcx.par_body_owners(|body_owner_def_id| {
2654
tcx.ensure().typeck(body_owner_def_id);

0 commit comments

Comments
 (0)