Skip to content

Commit 5486d72

Browse files
committed
Reduce visibilities.
Three of the modules don't need to be `pub`, and then `warn(unreachable_pub)` identifies a bunch more things that also shouldn't be `pub`, plus a couple of things that are unused.
1 parent 7a9bbd0 commit 5486d72

File tree

4 files changed

+25
-52
lines changed

4 files changed

+25
-52
lines changed

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,17 @@ use crate::traits::{self, ObligationCause, ObligationInspector, PredicateObligat
5656
pub mod at;
5757
pub mod canonical;
5858
mod context;
59-
pub mod free_regions;
59+
mod free_regions;
6060
mod freshen;
6161
mod lexical_region_resolve;
62-
pub mod opaque_types;
62+
mod opaque_types;
6363
pub mod outlives;
6464
mod projection;
6565
pub mod region_constraints;
6666
pub mod relate;
6767
pub mod resolve;
6868
pub(crate) mod snapshot;
69-
pub mod type_variable;
69+
mod type_variable;
7070

7171
#[must_use]
7272
#[derive(Debug)]

compiler/rustc_infer/src/infer/opaque_types/mod.rs

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use crate::traits::{self, Obligation};
1919

2020
mod table;
2121

22-
pub type OpaqueTypeMap<'tcx> = FxIndexMap<OpaqueTypeKey<'tcx>, OpaqueTypeDecl<'tcx>>;
23-
pub use table::{OpaqueTypeStorage, OpaqueTypeTable};
22+
pub(crate) type OpaqueTypeMap<'tcx> = FxIndexMap<OpaqueTypeKey<'tcx>, OpaqueTypeDecl<'tcx>>;
23+
pub(crate) use table::{OpaqueTypeStorage, OpaqueTypeTable};
2424

2525
use super::DefineOpaqueTypes;
2626

@@ -377,9 +377,9 @@ impl<'tcx> InferCtxt<'tcx> {
377377
///
378378
/// We ignore any type parameters because impl trait values are assumed to
379379
/// capture all the in-scope type parameters.
380-
pub struct ConstrainOpaqueTypeRegionVisitor<'tcx, OP: FnMut(ty::Region<'tcx>)> {
381-
pub tcx: TyCtxt<'tcx>,
382-
pub op: OP,
380+
struct ConstrainOpaqueTypeRegionVisitor<'tcx, OP: FnMut(ty::Region<'tcx>)> {
381+
tcx: TyCtxt<'tcx>,
382+
op: OP,
383383
}
384384

385385
impl<'tcx, OP> TypeVisitor<TyCtxt<'tcx>> for ConstrainOpaqueTypeRegionVisitor<'tcx, OP>
@@ -455,20 +455,6 @@ where
455455
}
456456
}
457457

458-
pub enum UseKind {
459-
DefiningUse,
460-
OpaqueUse,
461-
}
462-
463-
impl UseKind {
464-
pub fn is_defining(self) -> bool {
465-
match self {
466-
UseKind::DefiningUse => true,
467-
UseKind::OpaqueUse => false,
468-
}
469-
}
470-
}
471-
472458
impl<'tcx> InferCtxt<'tcx> {
473459
#[instrument(skip(self), level = "debug")]
474460
fn register_hidden_type(

compiler/rustc_infer/src/infer/opaque_types/table.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use super::{OpaqueTypeDecl, OpaqueTypeMap};
77
use crate::infer::snapshot::undo_log::{InferCtxtUndoLogs, UndoLog};
88

99
#[derive(Default, Debug, Clone)]
10-
pub struct OpaqueTypeStorage<'tcx> {
10+
pub(crate) struct OpaqueTypeStorage<'tcx> {
1111
/// Opaque types found in explicit return types and their
1212
/// associated fresh inference variable. Writeback resolves these
1313
/// variables to get the concrete type, which can be used to

compiler/rustc_infer/src/infer/type_variable.rs

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl<'tcx> Rollback<sv::UndoLog<ut::Delegate<TyVidEqKey<'tcx>>>> for TypeVariabl
2020
}
2121

2222
#[derive(Clone)]
23-
pub struct TypeVariableStorage<'tcx> {
23+
pub(crate) struct TypeVariableStorage<'tcx> {
2424
/// The origins of each type variable.
2525
values: IndexVec<TyVid, TypeVariableData>,
2626
/// Two variables are unified in `eq_relations` when we have a
@@ -29,7 +29,7 @@ pub struct TypeVariableStorage<'tcx> {
2929
eq_relations: ut::UnificationTableStorage<TyVidEqKey<'tcx>>,
3030
}
3131

32-
pub struct TypeVariableTable<'a, 'tcx> {
32+
pub(crate) struct TypeVariableTable<'a, 'tcx> {
3333
storage: &'a mut TypeVariableStorage<'tcx>,
3434

3535
undo_log: &'a mut InferCtxtUndoLogs<'tcx>,
@@ -50,22 +50,22 @@ pub(crate) struct TypeVariableData {
5050
}
5151

5252
#[derive(Copy, Clone, Debug)]
53-
pub enum TypeVariableValue<'tcx> {
53+
pub(crate) enum TypeVariableValue<'tcx> {
5454
Known { value: Ty<'tcx> },
5555
Unknown { universe: ty::UniverseIndex },
5656
}
5757

5858
impl<'tcx> TypeVariableValue<'tcx> {
5959
/// If this value is known, returns the type it is known to be.
6060
/// Otherwise, `None`.
61-
pub fn known(&self) -> Option<Ty<'tcx>> {
61+
pub(crate) fn known(&self) -> Option<Ty<'tcx>> {
6262
match *self {
6363
TypeVariableValue::Unknown { .. } => None,
6464
TypeVariableValue::Known { value } => Some(value),
6565
}
6666
}
6767

68-
pub fn is_unknown(&self) -> bool {
68+
pub(crate) fn is_unknown(&self) -> bool {
6969
match *self {
7070
TypeVariableValue::Unknown { .. } => true,
7171
TypeVariableValue::Known { .. } => false,
@@ -74,7 +74,7 @@ impl<'tcx> TypeVariableValue<'tcx> {
7474
}
7575

7676
impl<'tcx> TypeVariableStorage<'tcx> {
77-
pub fn new() -> TypeVariableStorage<'tcx> {
77+
pub(crate) fn new() -> TypeVariableStorage<'tcx> {
7878
TypeVariableStorage {
7979
values: Default::default(),
8080
eq_relations: ut::UnificationTableStorage::new(),
@@ -105,14 +105,14 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
105105
///
106106
/// Note that this function does not return care whether
107107
/// `vid` has been unified with something else or not.
108-
pub fn var_origin(&self, vid: ty::TyVid) -> TypeVariableOrigin {
108+
pub(crate) fn var_origin(&self, vid: ty::TyVid) -> TypeVariableOrigin {
109109
self.storage.values[vid].origin
110110
}
111111

112112
/// Records that `a == b`, depending on `dir`.
113113
///
114114
/// Precondition: neither `a` nor `b` are known.
115-
pub fn equate(&mut self, a: ty::TyVid, b: ty::TyVid) {
115+
pub(crate) fn equate(&mut self, a: ty::TyVid, b: ty::TyVid) {
116116
debug_assert!(self.probe(a).is_unknown());
117117
debug_assert!(self.probe(b).is_unknown());
118118
self.eq_relations().union(a, b);
@@ -121,7 +121,7 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
121121
/// Instantiates `vid` with the type `ty`.
122122
///
123123
/// Precondition: `vid` must not have been previously instantiated.
124-
pub fn instantiate(&mut self, vid: ty::TyVid, ty: Ty<'tcx>) {
124+
pub(crate) fn instantiate(&mut self, vid: ty::TyVid, ty: Ty<'tcx>) {
125125
let vid = self.root_var(vid);
126126
debug_assert!(!ty.is_ty_var(), "instantiating ty var with var: {vid:?} {ty:?}");
127127
debug_assert!(self.probe(vid).is_unknown());
@@ -143,7 +143,7 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
143143
/// - `origin`: indicates *why* the type variable was created.
144144
/// The code in this module doesn't care, but it can be useful
145145
/// for improving error messages.
146-
pub fn new_var(
146+
pub(crate) fn new_var(
147147
&mut self,
148148
universe: ty::UniverseIndex,
149149
origin: TypeVariableOrigin,
@@ -158,7 +158,7 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
158158
}
159159

160160
/// Returns the number of type variables created thus far.
161-
pub fn num_vars(&self) -> usize {
161+
pub(crate) fn num_vars(&self) -> usize {
162162
self.storage.values.len()
163163
}
164164

@@ -167,42 +167,29 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
167167
/// will yield the same root variable (per the union-find
168168
/// algorithm), so `root_var(a) == root_var(b)` implies that `a ==
169169
/// b` (transitively).
170-
pub fn root_var(&mut self, vid: ty::TyVid) -> ty::TyVid {
170+
pub(crate) fn root_var(&mut self, vid: ty::TyVid) -> ty::TyVid {
171171
self.eq_relations().find(vid).vid
172172
}
173173

174174
/// Retrieves the type to which `vid` has been instantiated, if
175175
/// any.
176-
pub fn probe(&mut self, vid: ty::TyVid) -> TypeVariableValue<'tcx> {
176+
pub(crate) fn probe(&mut self, vid: ty::TyVid) -> TypeVariableValue<'tcx> {
177177
self.inlined_probe(vid)
178178
}
179179

180180
/// An always-inlined variant of `probe`, for very hot call sites.
181181
#[inline(always)]
182-
pub fn inlined_probe(&mut self, vid: ty::TyVid) -> TypeVariableValue<'tcx> {
182+
pub(crate) fn inlined_probe(&mut self, vid: ty::TyVid) -> TypeVariableValue<'tcx> {
183183
self.eq_relations().inlined_probe_value(vid)
184184
}
185185

186-
/// If `t` is a type-inference variable, and it has been
187-
/// instantiated, then return the with which it was
188-
/// instantiated. Otherwise, returns `t`.
189-
pub fn replace_if_possible(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
190-
match *t.kind() {
191-
ty::Infer(ty::TyVar(v)) => match self.probe(v) {
192-
TypeVariableValue::Unknown { .. } => t,
193-
TypeVariableValue::Known { value } => value,
194-
},
195-
_ => t,
196-
}
197-
}
198-
199186
#[inline]
200187
fn eq_relations(&mut self) -> super::UnificationTable<'_, 'tcx, TyVidEqKey<'tcx>> {
201188
self.storage.eq_relations.with_log(self.undo_log)
202189
}
203190

204191
/// Returns a range of the type variables created during the snapshot.
205-
pub fn vars_since_snapshot(
192+
pub(crate) fn vars_since_snapshot(
206193
&mut self,
207194
value_count: usize,
208195
) -> (Range<TyVid>, Vec<TypeVariableOrigin>) {
@@ -215,7 +202,7 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
215202

216203
/// Returns indices of all variables that are not yet
217204
/// instantiated.
218-
pub fn unresolved_variables(&mut self) -> Vec<ty::TyVid> {
205+
pub(crate) fn unresolved_variables(&mut self) -> Vec<ty::TyVid> {
219206
(0..self.num_vars())
220207
.filter_map(|i| {
221208
let vid = ty::TyVid::from_usize(i);

0 commit comments

Comments
 (0)