Skip to content

Commit 3dd0f5f

Browse files
committed
Reduce visibilities, and add warn(unreachable_pub).
Lots of unnecessary `pub`s in this crate. Most are downgraded to `pub(super)`, though some don't need any visibility.
1 parent bd53aa3 commit 3dd0f5f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+129
-128
lines changed

compiler/rustc_mir_transform/src/abort_unwinding_calls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc_target::spec::PanicStrategy;
2020
/// This forces all unwinds, in panic=abort mode happening in foreign code, to
2121
/// trigger a process abort.
2222
#[derive(PartialEq)]
23-
pub struct AbortUnwindingCalls;
23+
pub(super) struct AbortUnwindingCalls;
2424

2525
impl<'tcx> MirPass<'tcx> for AbortUnwindingCalls {
2626
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {

compiler/rustc_mir_transform/src/add_call_guards.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ use rustc_middle::ty::TyCtxt;
44
use tracing::debug;
55

66
#[derive(PartialEq)]
7-
pub enum AddCallGuards {
7+
pub(super) enum AddCallGuards {
88
AllCallEdges,
99
CriticalCallEdges,
1010
}
11-
pub use self::AddCallGuards::*;
11+
pub(super) use self::AddCallGuards::*;
1212

1313
/**
1414
* Breaks outgoing critical edges for call terminators in the MIR.
@@ -37,7 +37,7 @@ impl<'tcx> MirPass<'tcx> for AddCallGuards {
3737
}
3838

3939
impl AddCallGuards {
40-
pub fn add_call_guards(&self, body: &mut Body<'_>) {
40+
pub(super) fn add_call_guards(&self, body: &mut Body<'_>) {
4141
let mut pred_count: IndexVec<_, _> =
4242
body.basic_blocks.predecessors().iter().map(|ps| ps.len()).collect();
4343
pred_count[START_BLOCK] += 1;

compiler/rustc_mir_transform/src/add_moves_for_packed_drops.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use crate::util;
3535
///
3636
/// The storage instructions are required to avoid stack space
3737
/// blowup.
38-
pub struct AddMovesForPackedDrops;
38+
pub(super) struct AddMovesForPackedDrops;
3939

4040
impl<'tcx> MirPass<'tcx> for AddMovesForPackedDrops {
4141
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
@@ -44,7 +44,7 @@ impl<'tcx> MirPass<'tcx> for AddMovesForPackedDrops {
4444
}
4545
}
4646

47-
pub fn add_moves_for_packed_drops<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
47+
fn add_moves_for_packed_drops<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
4848
let patch = add_moves_for_packed_drops_patch(tcx, body);
4949
patch.apply(body);
5050
}

compiler/rustc_mir_transform/src/add_retag.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_hir::LangItem;
88
use rustc_middle::mir::*;
99
use rustc_middle::ty::{self, Ty, TyCtxt};
1010

11-
pub struct AddRetag;
11+
pub(super) struct AddRetag;
1212

1313
/// Determine whether this type may contain a reference (or box), and thus needs retagging.
1414
/// We will only recurse `depth` times into Tuples/ADTs to bound the cost of this.

compiler/rustc_mir_transform/src/add_subtyping_projections.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use rustc_middle::mir::visit::MutVisitor;
44
use rustc_middle::mir::*;
55
use rustc_middle::ty::TyCtxt;
66

7-
pub struct Subtyper;
7+
pub(super) struct Subtyper;
88

9-
pub struct SubTypeChecker<'a, 'tcx> {
9+
struct SubTypeChecker<'a, 'tcx> {
1010
tcx: TyCtxt<'tcx>,
1111
patcher: MirPatch<'tcx>,
1212
local_decls: &'a IndexVec<Local, LocalDecl<'tcx>>,
@@ -52,7 +52,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for SubTypeChecker<'a, 'tcx> {
5252
// // gets transformed to
5353
// let temp: rval_ty = rval;
5454
// let place: place_ty = temp as place_ty;
55-
pub fn subtype_finder<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
55+
fn subtype_finder<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
5656
let patch = MirPatch::new(body);
5757
let mut checker = SubTypeChecker { tcx, patcher: patch, local_decls: &body.local_decls };
5858

compiler/rustc_mir_transform/src/check_alignment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_middle::ty::{self, ParamEnv, Ty, TyCtxt};
77
use rustc_session::Session;
88
use tracing::{debug, trace};
99

10-
pub struct CheckAlignment;
10+
pub(super) struct CheckAlignment;
1111

1212
impl<'tcx> MirPass<'tcx> for CheckAlignment {
1313
fn is_enabled(&self, sess: &Session) -> bool {

compiler/rustc_mir_transform/src/check_const_item_mutation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_span::Span;
88

99
use crate::{errors, MirLint};
1010

11-
pub struct CheckConstItemMutation;
11+
pub(super) struct CheckConstItemMutation;
1212

1313
impl<'tcx> MirLint<'tcx> for CheckConstItemMutation {
1414
fn run_lint(&self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {

compiler/rustc_mir_transform/src/check_packed_ref.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_middle::ty::{self, TyCtxt};
55

66
use crate::{errors, util, MirLint};
77

8-
pub struct CheckPackedRef;
8+
pub(super) struct CheckPackedRef;
99

1010
impl<'tcx> MirLint<'tcx> for CheckPackedRef {
1111
fn run_lint(&self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {

compiler/rustc_mir_transform/src/cleanup_post_borrowck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use rustc_middle::ty::TyCtxt;
2323

2424
use crate::MirPass;
2525

26-
pub struct CleanupPostBorrowck;
26+
pub(super) struct CleanupPostBorrowck;
2727

2828
impl<'tcx> MirPass<'tcx> for CleanupPostBorrowck {
2929
fn run_pass(&self, _tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {

compiler/rustc_mir_transform/src/copy_prop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::ssa::SsaLocals;
1717
/// where each of the locals is only assigned once.
1818
///
1919
/// We want to replace all those locals by `_a`, either copied or moved.
20-
pub struct CopyProp;
20+
pub(super) struct CopyProp;
2121

2222
impl<'tcx> MirPass<'tcx> for CopyProp {
2323
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {

compiler/rustc_mir_transform/src/coroutine.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
mod by_move_body;
5454
use std::{iter, ops};
5555

56-
pub use by_move_body::coroutine_by_move_body_def_id;
56+
pub(super) use by_move_body::coroutine_by_move_body_def_id;
5757
use rustc_data_structures::fx::FxHashSet;
5858
use rustc_errors::pluralize;
5959
use rustc_hir as hir;
@@ -85,7 +85,7 @@ use tracing::{debug, instrument, trace};
8585
use crate::deref_separator::deref_finder;
8686
use crate::{abort_unwinding_calls, errors, pass_manager as pm, simplify};
8787

88-
pub struct StateTransform;
88+
pub(super) struct StateTransform;
8989

9090
struct RenameLocalVisitor<'tcx> {
9191
from: Local,

compiler/rustc_mir_transform/src/coroutine/by_move_body.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ use rustc_middle::ty::{self, InstanceKind, Ty, TyCtxt, TypeVisitableExt};
8282
use rustc_span::symbol::kw;
8383
use rustc_target::abi::{FieldIdx, VariantIdx};
8484

85-
pub fn coroutine_by_move_body_def_id<'tcx>(
85+
pub(crate) fn coroutine_by_move_body_def_id<'tcx>(
8686
tcx: TyCtxt<'tcx>,
8787
coroutine_def_id: LocalDefId,
8888
) -> DefId {

compiler/rustc_mir_transform/src/cost_checker.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const CONST_SWITCH_BONUS: usize = 10;
1212

1313
/// Verify that the callee body is compatible with the caller.
1414
#[derive(Clone)]
15-
pub(crate) struct CostChecker<'b, 'tcx> {
15+
pub(super) struct CostChecker<'b, 'tcx> {
1616
tcx: TyCtxt<'tcx>,
1717
param_env: ParamEnv<'tcx>,
1818
penalty: usize,
@@ -22,7 +22,7 @@ pub(crate) struct CostChecker<'b, 'tcx> {
2222
}
2323

2424
impl<'b, 'tcx> CostChecker<'b, 'tcx> {
25-
pub fn new(
25+
pub(super) fn new(
2626
tcx: TyCtxt<'tcx>,
2727
param_env: ParamEnv<'tcx>,
2828
instance: Option<ty::Instance<'tcx>>,
@@ -36,7 +36,7 @@ impl<'b, 'tcx> CostChecker<'b, 'tcx> {
3636
/// Needed because the `CostChecker` is used sometimes for just blocks,
3737
/// and even the full `Inline` doesn't call `visit_body`, so there's nowhere
3838
/// to put this logic in the visitor.
39-
pub fn add_function_level_costs(&mut self) {
39+
pub(super) fn add_function_level_costs(&mut self) {
4040
fn is_call_like(bbd: &BasicBlockData<'_>) -> bool {
4141
use TerminatorKind::*;
4242
match bbd.terminator().kind {
@@ -64,7 +64,7 @@ impl<'b, 'tcx> CostChecker<'b, 'tcx> {
6464
}
6565
}
6666

67-
pub fn cost(&self) -> usize {
67+
pub(super) fn cost(&self) -> usize {
6868
usize::saturating_sub(self.penalty, self.bonus)
6969
}
7070

compiler/rustc_mir_transform/src/coverage/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pub mod query;
1+
pub(super) mod query;
22

33
mod counters;
44
mod graph;
@@ -33,7 +33,7 @@ use crate::MirPass;
3333
/// Inserts `StatementKind::Coverage` statements that either instrument the binary with injected
3434
/// counters, via intrinsic `llvm.instrprof.increment`, and/or inject metadata used during codegen
3535
/// to construct the coverage map.
36-
pub struct InstrumentCoverage;
36+
pub(super) struct InstrumentCoverage;
3737

3838
impl<'tcx> MirPass<'tcx> for InstrumentCoverage {
3939
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {

compiler/rustc_mir_transform/src/cross_crate_inline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_span::sym;
1010

1111
use crate::{inline, pass_manager as pm};
1212

13-
pub fn provide(providers: &mut Providers) {
13+
pub(super) fn provide(providers: &mut Providers) {
1414
providers.cross_crate_inlinable = cross_crate_inlinable;
1515
}
1616

compiler/rustc_mir_transform/src/ctfe_limit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use tracing::instrument;
1010

1111
use crate::MirPass;
1212

13-
pub struct CtfeLimit;
13+
pub(super) struct CtfeLimit;
1414

1515
impl<'tcx> MirPass<'tcx> for CtfeLimit {
1616
#[instrument(skip(self, _tcx, body))]

compiler/rustc_mir_transform/src/dataflow_const_prop.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use tracing::{debug, debug_span, instrument};
2626
const BLOCK_LIMIT: usize = 100;
2727
const PLACE_LIMIT: usize = 100;
2828

29-
pub struct DataflowConstProp;
29+
pub(super) struct DataflowConstProp;
3030

3131
impl<'tcx> MirPass<'tcx> for DataflowConstProp {
3232
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
@@ -332,7 +332,7 @@ impl<'tcx> ValueAnalysis<'tcx> for ConstAnalysis<'_, 'tcx> {
332332
}
333333

334334
impl<'a, 'tcx> ConstAnalysis<'a, 'tcx> {
335-
pub fn new(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, map: Map<'tcx>) -> Self {
335+
fn new(tcx: TyCtxt<'tcx>, body: &'a Body<'tcx>, map: Map<'tcx>) -> Self {
336336
let param_env = tcx.param_env_reveal_all_normalized(body.source.def_id());
337337
Self {
338338
map,

compiler/rustc_mir_transform/src/dead_store_elimination.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use crate::util::is_within_packed;
2828
///
2929
/// The `borrowed` set must be a `BitSet` of all the locals that are ever borrowed in this body. It
3030
/// can be generated via the [`borrowed_locals`] function.
31-
pub fn eliminate<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
31+
fn eliminate<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
3232
let borrowed_locals = borrowed_locals(body);
3333

3434
// If the user requests complete debuginfo, mark the locals that appear in it as live, so
@@ -127,7 +127,7 @@ pub fn eliminate<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
127127
}
128128
}
129129

130-
pub enum DeadStoreElimination {
130+
pub(super) enum DeadStoreElimination {
131131
Initial,
132132
Final,
133133
}

compiler/rustc_mir_transform/src/deduce_param_attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ fn type_will_always_be_passed_directly(ty: Ty<'_>) -> bool {
150150
/// body of the function instead of just the signature. These can be useful for optimization
151151
/// purposes on a best-effort basis. We compute them here and store them into the crate metadata so
152152
/// dependent crates can use them.
153-
pub fn deduced_param_attrs<'tcx>(
153+
pub(super) fn deduced_param_attrs<'tcx>(
154154
tcx: TyCtxt<'tcx>,
155155
def_id: LocalDefId,
156156
) -> &'tcx [DeducedParamAttrs] {

compiler/rustc_mir_transform/src/deduplicate_blocks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use tracing::debug;
1313

1414
use super::simplify::simplify_cfg;
1515

16-
pub struct DeduplicateBlocks;
16+
pub(super) struct DeduplicateBlocks;
1717

1818
impl<'tcx> MirPass<'tcx> for DeduplicateBlocks {
1919
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {

compiler/rustc_mir_transform/src/deref_separator.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ use rustc_middle::mir::visit::{MutVisitor, PlaceContext};
55
use rustc_middle::mir::*;
66
use rustc_middle::ty::TyCtxt;
77

8-
pub struct Derefer;
8+
pub(super) struct Derefer;
99

10-
pub struct DerefChecker<'a, 'tcx> {
10+
struct DerefChecker<'a, 'tcx> {
1111
tcx: TyCtxt<'tcx>,
1212
patcher: MirPatch<'tcx>,
1313
local_decls: &'a IndexVec<Local, LocalDecl<'tcx>>,
@@ -67,7 +67,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for DerefChecker<'a, 'tcx> {
6767
}
6868
}
6969

70-
pub fn deref_finder<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
70+
pub(super) fn deref_finder<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
7171
let patch = MirPatch::new(body);
7272
let mut checker = DerefChecker { tcx, patcher: patch, local_decls: &body.local_decls };
7373

compiler/rustc_mir_transform/src/dest_prop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ use tracing::{debug, trace};
148148

149149
use crate::MirPass;
150150

151-
pub struct DestinationPropagation;
151+
pub(super) struct DestinationPropagation;
152152

153153
impl<'tcx> MirPass<'tcx> for DestinationPropagation {
154154
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {

compiler/rustc_mir_transform/src/dump_mir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_session::config::{OutFileName, OutputType};
99

1010
use crate::MirPass;
1111

12-
pub struct Marker(pub &'static str);
12+
pub(super) struct Marker(pub &'static str);
1313

1414
impl<'tcx> MirPass<'tcx> for Marker {
1515
fn name(&self) -> &'static str {

compiler/rustc_mir_transform/src/early_otherwise_branch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ use super::simplify::simplify_cfg;
9090
/// | ... |
9191
/// =================
9292
/// ```
93-
pub struct EarlyOtherwiseBranch;
93+
pub(super) struct EarlyOtherwiseBranch;
9494

9595
impl<'tcx> MirPass<'tcx> for EarlyOtherwiseBranch {
9696
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {

compiler/rustc_mir_transform/src/elaborate_box_derefs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_middle::ty::{Ty, TyCtxt};
1111
use rustc_target::abi::FieldIdx;
1212

1313
/// Constructs the types used when accessing a Box's pointer
14-
pub fn build_ptr_tys<'tcx>(
14+
fn build_ptr_tys<'tcx>(
1515
tcx: TyCtxt<'tcx>,
1616
pointee: Ty<'tcx>,
1717
unique_did: DefId,
@@ -26,7 +26,7 @@ pub fn build_ptr_tys<'tcx>(
2626
}
2727

2828
/// Constructs the projection needed to access a Box's pointer
29-
pub fn build_projection<'tcx>(
29+
pub(super) fn build_projection<'tcx>(
3030
unique_ty: Ty<'tcx>,
3131
nonnull_ty: Ty<'tcx>,
3232
ptr_ty: Ty<'tcx>,
@@ -86,7 +86,7 @@ impl<'tcx, 'a> MutVisitor<'tcx> for ElaborateBoxDerefVisitor<'tcx, 'a> {
8686
}
8787
}
8888

89-
pub struct ElaborateBoxDerefs;
89+
pub(super) struct ElaborateBoxDerefs;
9090

9191
impl<'tcx> MirPass<'tcx> for ElaborateBoxDerefs {
9292
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {

compiler/rustc_mir_transform/src/elaborate_drops.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use crate::deref_separator::deref_finder;
4747
/// }
4848
/// }
4949
/// ```
50-
pub struct ElaborateDrops;
50+
pub(super) struct ElaborateDrops;
5151

5252
impl<'tcx> MirPass<'tcx> for ElaborateDrops {
5353
#[instrument(level = "trace", skip(self, tcx, body))]

compiler/rustc_mir_transform/src/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl<'a, P: std::fmt::Debug> LintDiagnostic<'a, ()> for AssertLint<P> {
6464
}
6565

6666
impl AssertLintKind {
67-
pub fn lint(&self) -> &'static Lint {
67+
pub(crate) fn lint(&self) -> &'static Lint {
6868
match self {
6969
AssertLintKind::ArithmeticOverflow => lint::builtin::ARITHMETIC_OVERFLOW,
7070
AssertLintKind::UnconditionalPanic => lint::builtin::UNCONDITIONAL_PANIC,

compiler/rustc_mir_transform/src/function_item_references.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_target::spec::abi::Abi;
1111

1212
use crate::{errors, MirLint};
1313

14-
pub struct FunctionItemReferences;
14+
pub(super) struct FunctionItemReferences;
1515

1616
impl<'tcx> MirLint<'tcx> for FunctionItemReferences {
1717
fn run_lint(&self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {

compiler/rustc_mir_transform/src/gvn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ use tracing::{debug, instrument, trace};
109109

110110
use crate::ssa::{AssignedValue, SsaLocals};
111111

112-
pub struct GVN;
112+
pub(super) struct GVN;
113113

114114
impl<'tcx> MirPass<'tcx> for GVN {
115115
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {

compiler/rustc_mir_transform/src/inline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub(crate) mod cycle;
3232

3333
const TOP_DOWN_DEPTH_LIMIT: usize = 5;
3434

35-
pub struct Inline;
35+
pub(super) struct Inline;
3636

3737
#[derive(Copy, Clone, Debug)]
3838
struct CallSite<'tcx> {

0 commit comments

Comments
 (0)