From 2d2755ff97d4c1909dfcd3e2c1fce806a6550919 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 1 Oct 2024 16:40:22 +1000 Subject: [PATCH] Reduce visibilities some more. It helps people reading the code understand how widely things are used. --- compiler/rustc_infer/src/infer/mod.rs | 9 +++++---- .../rustc_infer/src/infer/opaque_types/table.rs | 2 +- compiler/rustc_infer/src/infer/outlives/mod.rs | 2 +- .../rustc_infer/src/infer/outlives/verify.rs | 12 ++++++------ .../src/infer/region_constraints/mod.rs | 2 +- compiler/rustc_infer/src/infer/relate/combine.rs | 16 ++++++++-------- compiler/rustc_infer/src/infer/relate/mod.rs | 2 +- .../src/infer/relate/type_relating.rs | 4 ++-- compiler/rustc_infer/src/infer/snapshot/mod.rs | 2 +- 9 files changed, 26 insertions(+), 25 deletions(-) diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index c98604de839..8714e854114 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -14,7 +14,8 @@ GenericKind, RegionConstraintCollector, RegionConstraintStorage, VarInfos, VerifyBound, }; pub use relate::StructurallyRelateAliases; -pub use relate::combine::{CombineFields, PredicateEmittingRelation}; +use relate::combine::CombineFields; +pub use relate::combine::PredicateEmittingRelation; use rustc_data_structures::captures::Captures; use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; use rustc_data_structures::sync::Lrc; @@ -75,7 +76,7 @@ pub struct InferOk<'tcx, T> { } pub type InferResult<'tcx, T> = Result, TypeError<'tcx>>; -pub type FixupResult = Result; // "fixup result" +pub(crate) type FixupResult = Result; // "fixup result" pub(crate) type UnificationTable<'a, 'tcx, T> = ut::UnificationTable< ut::InPlace, &'a mut InferCtxtUndoLogs<'tcx>>, @@ -200,7 +201,7 @@ fn type_variables(&mut self) -> type_variable::TypeVariableTable<'_, 'tcx> { } #[inline] - pub fn opaque_types(&mut self) -> opaque_types::OpaqueTypeTable<'_, 'tcx> { + fn opaque_types(&mut self) -> opaque_types::OpaqueTypeTable<'_, 'tcx> { self.opaque_type_storage.with_log(&mut self.undo_log) } @@ -1351,7 +1352,7 @@ fn replace_const(&mut self, bv: ty::BoundVar) -> ty::Const<'tcx> { } /// See the [`region_constraints::RegionConstraintCollector::verify_generic_bound`] method. - pub fn verify_generic_bound( + pub(crate) fn verify_generic_bound( &self, origin: SubregionOrigin<'tcx>, kind: GenericKind<'tcx>, diff --git a/compiler/rustc_infer/src/infer/opaque_types/table.rs b/compiler/rustc_infer/src/infer/opaque_types/table.rs index 6e4cc65bec3..047d8edad3d 100644 --- a/compiler/rustc_infer/src/infer/opaque_types/table.rs +++ b/compiler/rustc_infer/src/infer/opaque_types/table.rs @@ -46,7 +46,7 @@ fn drop(&mut self) { } } -pub struct OpaqueTypeTable<'a, 'tcx> { +pub(crate) struct OpaqueTypeTable<'a, 'tcx> { storage: &'a mut OpaqueTypeStorage<'tcx>, undo_log: &'a mut InferCtxtUndoLogs<'tcx>, diff --git a/compiler/rustc_infer/src/infer/outlives/mod.rs b/compiler/rustc_infer/src/infer/outlives/mod.rs index f5c873b0375..a270f9322f3 100644 --- a/compiler/rustc_infer/src/infer/outlives/mod.rs +++ b/compiler/rustc_infer/src/infer/outlives/mod.rs @@ -14,7 +14,7 @@ pub mod for_liveness; pub mod obligations; pub mod test_type_match; -pub mod verify; +pub(crate) mod verify; #[instrument(level = "debug", skip(param_env), ret)] pub fn explicit_outlives_bounds<'tcx>( diff --git a/compiler/rustc_infer/src/infer/outlives/verify.rs b/compiler/rustc_infer/src/infer/outlives/verify.rs index 74a80a1b9aa..247fbc25965 100644 --- a/compiler/rustc_infer/src/infer/outlives/verify.rs +++ b/compiler/rustc_infer/src/infer/outlives/verify.rs @@ -15,7 +15,7 @@ /// via a "delegate" of type `D` -- this is usually the `infcx`, which /// accrues them into the `region_obligations` code, but for NLL we /// use something else. -pub struct VerifyBoundCx<'cx, 'tcx> { +pub(crate) struct VerifyBoundCx<'cx, 'tcx> { tcx: TyCtxt<'tcx>, region_bound_pairs: &'cx RegionBoundPairs<'tcx>, /// During borrowck, if there are no outlives bounds on a generic @@ -28,7 +28,7 @@ pub struct VerifyBoundCx<'cx, 'tcx> { } impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> { - pub fn new( + pub(crate) fn new( tcx: TyCtxt<'tcx>, region_bound_pairs: &'cx RegionBoundPairs<'tcx>, implicit_region_bound: Option>, @@ -38,7 +38,7 @@ pub fn new( } #[instrument(level = "debug", skip(self))] - pub fn param_or_placeholder_bound(&self, ty: Ty<'tcx>) -> VerifyBound<'tcx> { + pub(crate) fn param_or_placeholder_bound(&self, ty: Ty<'tcx>) -> VerifyBound<'tcx> { // Start with anything like `T: 'a` we can scrape from the // environment. If the environment contains something like // `for<'a> T: 'a`, then we know that `T` outlives everything. @@ -92,7 +92,7 @@ pub fn param_or_placeholder_bound(&self, ty: Ty<'tcx>) -> VerifyBound<'tcx> { /// the clause from the environment only applies if `'0 = 'a`, /// which we don't know yet. But we would still include `'b` in /// this list. - pub fn approx_declared_bounds_from_env( + pub(crate) fn approx_declared_bounds_from_env( &self, alias_ty: ty::AliasTy<'tcx>, ) -> Vec> { @@ -101,7 +101,7 @@ pub fn approx_declared_bounds_from_env( } #[instrument(level = "debug", skip(self))] - pub fn alias_bound(&self, alias_ty: ty::AliasTy<'tcx>) -> VerifyBound<'tcx> { + pub(crate) fn alias_bound(&self, alias_ty: ty::AliasTy<'tcx>) -> VerifyBound<'tcx> { let alias_ty_as_ty = alias_ty.to_ty(self.tcx); // Search the env for where clauses like `P: 'a`. @@ -285,7 +285,7 @@ fn declared_generic_bounds_from_env_for_erased_ty( /// /// This is for simplicity, and because we are not really smart /// enough to cope with such bounds anywhere. - pub fn declared_bounds_from_definition( + pub(crate) fn declared_bounds_from_definition( &self, alias_ty: ty::AliasTy<'tcx>, ) -> impl Iterator> { diff --git a/compiler/rustc_infer/src/infer/region_constraints/mod.rs b/compiler/rustc_infer/src/infer/region_constraints/mod.rs index 82f7668b2d2..a6d1d05f6e1 100644 --- a/compiler/rustc_infer/src/infer/region_constraints/mod.rs +++ b/compiler/rustc_infer/src/infer/region_constraints/mod.rs @@ -304,7 +304,7 @@ pub struct RegionVariableInfo { pub universe: ty::UniverseIndex, } -pub struct RegionSnapshot { +pub(crate) struct RegionSnapshot { any_unifications: bool, } diff --git a/compiler/rustc_infer/src/infer/relate/combine.rs b/compiler/rustc_infer/src/infer/relate/combine.rs index 4a8c7387ddc..450437f2176 100644 --- a/compiler/rustc_infer/src/infer/relate/combine.rs +++ b/compiler/rustc_infer/src/infer/relate/combine.rs @@ -33,7 +33,7 @@ use crate::traits::{Obligation, PredicateObligation}; #[derive(Clone)] -pub struct CombineFields<'infcx, 'tcx> { +pub(crate) struct CombineFields<'infcx, 'tcx> { pub infcx: &'infcx InferCtxt<'tcx>, // Immutable fields pub trace: TypeTrace<'tcx>, @@ -47,7 +47,7 @@ pub struct CombineFields<'infcx, 'tcx> { } impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> { - pub fn new( + pub(crate) fn new( infcx: &'infcx InferCtxt<'tcx>, trace: TypeTrace<'tcx>, param_env: ty::ParamEnv<'tcx>, @@ -283,22 +283,22 @@ fn unify_effect_variable(&self, vid: ty::EffectVid, val: ty::Const<'tcx>) -> ty: } impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> { - pub fn tcx(&self) -> TyCtxt<'tcx> { + pub(crate) fn tcx(&self) -> TyCtxt<'tcx> { self.infcx.tcx } - pub fn equate<'a>( + pub(crate) fn equate<'a>( &'a mut self, structurally_relate_aliases: StructurallyRelateAliases, ) -> TypeRelating<'a, 'infcx, 'tcx> { TypeRelating::new(self, structurally_relate_aliases, ty::Invariant) } - pub fn sub<'a>(&'a mut self) -> TypeRelating<'a, 'infcx, 'tcx> { + pub(crate) fn sub<'a>(&'a mut self) -> TypeRelating<'a, 'infcx, 'tcx> { TypeRelating::new(self, StructurallyRelateAliases::No, ty::Covariant) } - pub fn sup<'a>(&'a mut self) -> TypeRelating<'a, 'infcx, 'tcx> { + pub(crate) fn sup<'a>(&'a mut self) -> TypeRelating<'a, 'infcx, 'tcx> { TypeRelating::new(self, StructurallyRelateAliases::No, ty::Contravariant) } @@ -310,14 +310,14 @@ pub(crate) fn glb<'a>(&'a mut self) -> LatticeOp<'a, 'infcx, 'tcx> { LatticeOp::new(self, LatticeOpKind::Glb) } - pub fn register_obligations( + pub(crate) fn register_obligations( &mut self, obligations: impl IntoIterator>>, ) { self.goals.extend(obligations); } - pub fn register_predicates( + pub(crate) fn register_predicates( &mut self, obligations: impl IntoIterator, ty::Predicate<'tcx>>>, ) { diff --git a/compiler/rustc_infer/src/infer/relate/mod.rs b/compiler/rustc_infer/src/infer/relate/mod.rs index edc0c4f078a..85158faa65d 100644 --- a/compiler/rustc_infer/src/infer/relate/mod.rs +++ b/compiler/rustc_infer/src/infer/relate/mod.rs @@ -5,7 +5,7 @@ pub use rustc_middle::ty::relate::RelateResult; pub use rustc_next_trait_solver::relate::*; -pub use self::combine::{CombineFields, PredicateEmittingRelation}; +pub use self::combine::PredicateEmittingRelation; #[allow(hidden_glob_reexports)] pub(super) mod combine; diff --git a/compiler/rustc_infer/src/infer/relate/type_relating.rs b/compiler/rustc_infer/src/infer/relate/type_relating.rs index 7acfea643dd..7537ceec307 100644 --- a/compiler/rustc_infer/src/infer/relate/type_relating.rs +++ b/compiler/rustc_infer/src/infer/relate/type_relating.rs @@ -13,7 +13,7 @@ use crate::infer::{DefineOpaqueTypes, InferCtxt, SubregionOrigin}; /// Enforce that `a` is equal to or a subtype of `b`. -pub struct TypeRelating<'combine, 'a, 'tcx> { +pub(crate) struct TypeRelating<'combine, 'a, 'tcx> { // Immutable except for the `InferCtxt` and the // resulting nested `goals`. fields: &'combine mut CombineFields<'a, 'tcx>, @@ -49,7 +49,7 @@ pub struct TypeRelating<'combine, 'a, 'tcx> { } impl<'combine, 'infcx, 'tcx> TypeRelating<'combine, 'infcx, 'tcx> { - pub fn new( + pub(crate) fn new( f: &'combine mut CombineFields<'infcx, 'tcx>, structurally_relate_aliases: StructurallyRelateAliases, ambient_variance: ty::Variance, diff --git a/compiler/rustc_infer/src/infer/snapshot/mod.rs b/compiler/rustc_infer/src/infer/snapshot/mod.rs index 964fb1f6819..07a482c2f9a 100644 --- a/compiler/rustc_infer/src/infer/snapshot/mod.rs +++ b/compiler/rustc_infer/src/infer/snapshot/mod.rs @@ -5,7 +5,7 @@ use super::InferCtxt; use super::region_constraints::RegionSnapshot; -mod fudge; +pub(crate) mod fudge; pub(crate) mod undo_log; use undo_log::{Snapshot, UndoLog};