Skip to content

Commit bdacdfe

Browse files
committed
Minimize visibilities.
This makes it much clearer which things are used outside the crate.
1 parent 04a3187 commit bdacdfe

24 files changed

+188
-179
lines changed

compiler/rustc_codegen_ssa/src/back/archive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ pub trait ArchiveBuilderBuilder {
157157
}
158158
}
159159

160-
pub fn create_mingw_dll_import_lib(
160+
fn create_mingw_dll_import_lib(
161161
sess: &Session,
162162
lib_name: &str,
163163
import_name_and_ordinal_vector: Vec<(String, Option<u16>)>,

compiler/rustc_codegen_ssa/src/back/command.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::{fmt, io, mem};
88
use rustc_target::spec::LldFlavor;
99

1010
#[derive(Clone)]
11-
pub struct Command {
11+
pub(crate) struct Command {
1212
program: Program,
1313
args: Vec<OsString>,
1414
env: Vec<(OsString, OsString)>,
@@ -23,28 +23,28 @@ enum Program {
2323
}
2424

2525
impl Command {
26-
pub fn new<P: AsRef<OsStr>>(program: P) -> Command {
26+
pub(crate) fn new<P: AsRef<OsStr>>(program: P) -> Command {
2727
Command::_new(Program::Normal(program.as_ref().to_owned()))
2828
}
2929

30-
pub fn bat_script<P: AsRef<OsStr>>(program: P) -> Command {
30+
pub(crate) fn bat_script<P: AsRef<OsStr>>(program: P) -> Command {
3131
Command::_new(Program::CmdBatScript(program.as_ref().to_owned()))
3232
}
3333

34-
pub fn lld<P: AsRef<OsStr>>(program: P, flavor: LldFlavor) -> Command {
34+
pub(crate) fn lld<P: AsRef<OsStr>>(program: P, flavor: LldFlavor) -> Command {
3535
Command::_new(Program::Lld(program.as_ref().to_owned(), flavor))
3636
}
3737

3838
fn _new(program: Program) -> Command {
3939
Command { program, args: Vec::new(), env: Vec::new(), env_remove: Vec::new() }
4040
}
4141

42-
pub fn arg<P: AsRef<OsStr>>(&mut self, arg: P) -> &mut Command {
42+
pub(crate) fn arg<P: AsRef<OsStr>>(&mut self, arg: P) -> &mut Command {
4343
self._arg(arg.as_ref());
4444
self
4545
}
4646

47-
pub fn args<I>(&mut self, args: I) -> &mut Command
47+
pub(crate) fn args<I>(&mut self, args: I) -> &mut Command
4848
where
4949
I: IntoIterator<Item: AsRef<OsStr>>,
5050
{
@@ -58,7 +58,7 @@ impl Command {
5858
self.args.push(arg.to_owned());
5959
}
6060

61-
pub fn env<K, V>(&mut self, key: K, value: V) -> &mut Command
61+
pub(crate) fn env<K, V>(&mut self, key: K, value: V) -> &mut Command
6262
where
6363
K: AsRef<OsStr>,
6464
V: AsRef<OsStr>,
@@ -71,7 +71,7 @@ impl Command {
7171
self.env.push((key.to_owned(), value.to_owned()));
7272
}
7373

74-
pub fn env_remove<K>(&mut self, key: K) -> &mut Command
74+
pub(crate) fn env_remove<K>(&mut self, key: K) -> &mut Command
7575
where
7676
K: AsRef<OsStr>,
7777
{
@@ -83,11 +83,11 @@ impl Command {
8383
self.env_remove.push(key.to_owned());
8484
}
8585

86-
pub fn output(&mut self) -> io::Result<Output> {
86+
pub(crate) fn output(&mut self) -> io::Result<Output> {
8787
self.command().output()
8888
}
8989

90-
pub fn command(&self) -> process::Command {
90+
pub(crate) fn command(&self) -> process::Command {
9191
let mut ret = match self.program {
9292
Program::Normal(ref p) => process::Command::new(p),
9393
Program::CmdBatScript(ref p) => {
@@ -111,17 +111,17 @@ impl Command {
111111

112112
// extensions
113113

114-
pub fn get_args(&self) -> &[OsString] {
114+
pub(crate) fn get_args(&self) -> &[OsString] {
115115
&self.args
116116
}
117117

118-
pub fn take_args(&mut self) -> Vec<OsString> {
118+
pub(crate) fn take_args(&mut self) -> Vec<OsString> {
119119
mem::take(&mut self.args)
120120
}
121121

122122
/// Returns a `true` if we're pretty sure that this'll blow OS spawn limits,
123123
/// or `false` if we should attempt to spawn and see what the OS says.
124-
pub fn very_likely_to_exceed_some_spawn_limit(&self) -> bool {
124+
pub(crate) fn very_likely_to_exceed_some_spawn_limit(&self) -> bool {
125125
// We mostly only care about Windows in this method, on Unix the limits
126126
// can be gargantuan anyway so we're pretty unlikely to hit them
127127
if cfg!(unix) {

compiler/rustc_codegen_ssa/src/back/linker.rs

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use crate::errors;
2828
/// and prevent inspection of linker output in case of errors, which we occasionally do.
2929
/// This should be acceptable because other messages from rustc are in English anyway,
3030
/// and may also be desirable to improve searchability of the linker diagnostics.
31-
pub fn disable_localization(linker: &mut Command) {
31+
pub(crate) fn disable_localization(linker: &mut Command) {
3232
// No harm in setting both env vars simultaneously.
3333
// Unix-style linkers.
3434
linker.env("LC_ALL", "C");
@@ -39,7 +39,7 @@ pub fn disable_localization(linker: &mut Command) {
3939
/// The third parameter is for env vars, used on windows to set up the
4040
/// path for MSVC to find its DLLs, and gcc to find its bundled
4141
/// toolchain
42-
pub fn get_linker<'a>(
42+
pub(crate) fn get_linker<'a>(
4343
sess: &'a Session,
4444
linker: &Path,
4545
flavor: LinkerFlavor,
@@ -213,28 +213,36 @@ fn link_or_cc_args<L: Linker + ?Sized>(
213213
macro_rules! generate_arg_methods {
214214
($($ty:ty)*) => { $(
215215
impl $ty {
216-
pub fn verbatim_args(&mut self, args: impl IntoIterator<Item: AsRef<OsStr>>) -> &mut Self {
216+
#[allow(unused)]
217+
pub(crate) fn verbatim_args(&mut self, args: impl IntoIterator<Item: AsRef<OsStr>>) -> &mut Self {
217218
verbatim_args(self, args)
218219
}
219-
pub fn verbatim_arg(&mut self, arg: impl AsRef<OsStr>) -> &mut Self {
220+
#[allow(unused)]
221+
pub(crate) fn verbatim_arg(&mut self, arg: impl AsRef<OsStr>) -> &mut Self {
220222
verbatim_args(self, iter::once(arg))
221223
}
222-
pub fn link_args(&mut self, args: impl IntoIterator<Item: AsRef<OsStr>, IntoIter: ExactSizeIterator>) -> &mut Self {
224+
#[allow(unused)]
225+
pub(crate) fn link_args(&mut self, args: impl IntoIterator<Item: AsRef<OsStr>, IntoIter: ExactSizeIterator>) -> &mut Self {
223226
link_args(self, args)
224227
}
225-
pub fn link_arg(&mut self, arg: impl AsRef<OsStr>) -> &mut Self {
228+
#[allow(unused)]
229+
pub(crate) fn link_arg(&mut self, arg: impl AsRef<OsStr>) -> &mut Self {
226230
link_args(self, iter::once(arg))
227231
}
228-
pub fn cc_args(&mut self, args: impl IntoIterator<Item: AsRef<OsStr>>) -> &mut Self {
232+
#[allow(unused)]
233+
pub(crate) fn cc_args(&mut self, args: impl IntoIterator<Item: AsRef<OsStr>>) -> &mut Self {
229234
cc_args(self, args)
230235
}
231-
pub fn cc_arg(&mut self, arg: impl AsRef<OsStr>) -> &mut Self {
236+
#[allow(unused)]
237+
pub(crate) fn cc_arg(&mut self, arg: impl AsRef<OsStr>) -> &mut Self {
232238
cc_args(self, iter::once(arg))
233239
}
234-
pub fn link_or_cc_args(&mut self, args: impl IntoIterator<Item: AsRef<OsStr>>) -> &mut Self {
240+
#[allow(unused)]
241+
pub(crate) fn link_or_cc_args(&mut self, args: impl IntoIterator<Item: AsRef<OsStr>>) -> &mut Self {
235242
link_or_cc_args(self, args)
236243
}
237-
pub fn link_or_cc_arg(&mut self, arg: impl AsRef<OsStr>) -> &mut Self {
244+
#[allow(unused)]
245+
pub(crate) fn link_or_cc_arg(&mut self, arg: impl AsRef<OsStr>) -> &mut Self {
238246
link_or_cc_args(self, iter::once(arg))
239247
}
240248
}
@@ -261,7 +269,7 @@ generate_arg_methods! {
261269
/// represents the meaning of each option being passed down. This trait is then
262270
/// used to dispatch on whether a GNU-like linker (generally `ld.exe`) or an
263271
/// MSVC linker (e.g., `link.exe`) is being used.
264-
pub trait Linker {
272+
pub(crate) trait Linker {
265273
fn cmd(&mut self) -> &mut Command;
266274
fn is_cc(&self) -> bool {
267275
false
@@ -312,12 +320,12 @@ pub trait Linker {
312320
}
313321

314322
impl dyn Linker + '_ {
315-
pub fn take_cmd(&mut self) -> Command {
323+
pub(crate) fn take_cmd(&mut self) -> Command {
316324
mem::replace(self.cmd(), Command::new(""))
317325
}
318326
}
319327

320-
pub struct GccLinker<'a> {
328+
struct GccLinker<'a> {
321329
cmd: Command,
322330
sess: &'a Session,
323331
target_cpu: &'a str,
@@ -847,7 +855,7 @@ impl<'a> Linker for GccLinker<'a> {
847855
}
848856
}
849857

850-
pub struct MsvcLinker<'a> {
858+
struct MsvcLinker<'a> {
851859
cmd: Command,
852860
sess: &'a Session,
853861
}
@@ -1095,7 +1103,7 @@ impl<'a> Linker for MsvcLinker<'a> {
10951103
}
10961104
}
10971105

1098-
pub struct EmLinker<'a> {
1106+
struct EmLinker<'a> {
10991107
cmd: Command,
11001108
sess: &'a Session,
11011109
}
@@ -1212,7 +1220,7 @@ impl<'a> Linker for EmLinker<'a> {
12121220
}
12131221
}
12141222

1215-
pub struct WasmLd<'a> {
1223+
struct WasmLd<'a> {
12161224
cmd: Command,
12171225
sess: &'a Session,
12181226
}
@@ -1396,7 +1404,7 @@ impl<'a> WasmLd<'a> {
13961404
}
13971405

13981406
/// Linker shepherd script for L4Re (Fiasco)
1399-
pub struct L4Bender<'a> {
1407+
struct L4Bender<'a> {
14001408
cmd: Command,
14011409
sess: &'a Session,
14021410
hinted_static: bool,
@@ -1502,7 +1510,7 @@ impl<'a> Linker for L4Bender<'a> {
15021510
}
15031511

15041512
impl<'a> L4Bender<'a> {
1505-
pub fn new(cmd: Command, sess: &'a Session) -> L4Bender<'a> {
1513+
fn new(cmd: Command, sess: &'a Session) -> L4Bender<'a> {
15061514
L4Bender { cmd, sess, hinted_static: false }
15071515
}
15081516

@@ -1515,14 +1523,14 @@ impl<'a> L4Bender<'a> {
15151523
}
15161524

15171525
/// Linker for AIX.
1518-
pub struct AixLinker<'a> {
1526+
struct AixLinker<'a> {
15191527
cmd: Command,
15201528
sess: &'a Session,
15211529
hinted_static: Option<bool>,
15221530
}
15231531

15241532
impl<'a> AixLinker<'a> {
1525-
pub fn new(cmd: Command, sess: &'a Session) -> AixLinker<'a> {
1533+
fn new(cmd: Command, sess: &'a Session) -> AixLinker<'a> {
15261534
AixLinker { cmd, sess, hinted_static: None }
15271535
}
15281536

@@ -1750,7 +1758,7 @@ pub(crate) fn linked_symbols(
17501758

17511759
/// Much simplified and explicit CLI for the NVPTX linker. The linker operates
17521760
/// with bitcode and uses LLVM backend to generate a PTX assembly.
1753-
pub struct PtxLinker<'a> {
1761+
struct PtxLinker<'a> {
17541762
cmd: Command,
17551763
sess: &'a Session,
17561764
}
@@ -1816,7 +1824,7 @@ impl<'a> Linker for PtxLinker<'a> {
18161824
}
18171825

18181826
/// The `self-contained` LLVM bitcode linker
1819-
pub struct LlbcLinker<'a> {
1827+
struct LlbcLinker<'a> {
18201828
cmd: Command,
18211829
sess: &'a Session,
18221830
}
@@ -1887,7 +1895,7 @@ impl<'a> Linker for LlbcLinker<'a> {
18871895
fn linker_plugin_lto(&mut self) {}
18881896
}
18891897

1890-
pub struct BpfLinker<'a> {
1898+
struct BpfLinker<'a> {
18911899
cmd: Command,
18921900
sess: &'a Session,
18931901
}

compiler/rustc_codegen_ssa/src/back/metadata.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use rustc_target::spec::{ef_avr_arch, RelocModel, Target};
3232
/// <dd>The metadata can be found in the `.rustc` section of the shared library.</dd>
3333
/// </dl>
3434
#[derive(Debug)]
35-
pub struct DefaultMetadataLoader;
35+
pub(crate) struct DefaultMetadataLoader;
3636

3737
static AIX_METADATA_SYMBOL_NAME: &'static str = "__aix_rust_metadata";
3838

@@ -416,7 +416,7 @@ fn macho_is_arm64e(target: &Target) -> bool {
416416
target.llvm_target.starts_with("arm64e")
417417
}
418418

419-
pub enum MetadataPosition {
419+
pub(crate) enum MetadataPosition {
420420
First,
421421
Last,
422422
}
@@ -452,7 +452,7 @@ pub enum MetadataPosition {
452452
/// * ELF - All other targets are similar to Windows in that there's a
453453
/// `SHF_EXCLUDE` flag we can set on sections in an object file to get
454454
/// automatically removed from the final output.
455-
pub fn create_wrapper_file(
455+
pub(crate) fn create_wrapper_file(
456456
sess: &Session,
457457
section_name: String,
458458
data: &[u8],
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
pub mod archive;
2-
pub mod command;
2+
pub(crate) mod command;
33
pub mod link;
4-
pub mod linker;
4+
pub(crate) mod linker;
55
pub mod lto;
66
pub mod metadata;
7-
pub mod rpath;
7+
pub(crate) mod rpath;
88
pub mod symbol_export;
99
pub mod write;

compiler/rustc_codegen_ssa/src/back/rpath.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ use rustc_data_structures::fx::FxHashSet;
66
use rustc_fs_util::try_canonicalize;
77
use tracing::debug;
88

9-
pub struct RPathConfig<'a> {
9+
pub(super) struct RPathConfig<'a> {
1010
pub libs: &'a [&'a Path],
1111
pub out_filename: PathBuf,
1212
pub is_like_osx: bool,
1313
pub linker_is_gnu: bool,
1414
}
1515

16-
pub fn get_rpath_flags(config: &RPathConfig<'_>) -> Vec<OsString> {
16+
pub(super) fn get_rpath_flags(config: &RPathConfig<'_>) -> Vec<OsString> {
1717
debug!("preparing the RPATH!");
1818

1919
let rpaths = get_rpaths(config);

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use tracing::debug;
1818

1919
use crate::base::allocator_kind_for_codegen;
2020

21-
pub fn threshold(tcx: TyCtxt<'_>) -> SymbolExportLevel {
21+
fn threshold(tcx: TyCtxt<'_>) -> SymbolExportLevel {
2222
crates_export_threshold(tcx.crate_types())
2323
}
2424

@@ -484,7 +484,7 @@ fn is_unreachable_local_definition_provider(tcx: TyCtxt<'_>, def_id: LocalDefId)
484484
!tcx.reachable_set(()).contains(&def_id)
485485
}
486486

487-
pub fn provide(providers: &mut Providers) {
487+
pub(crate) fn provide(providers: &mut Providers) {
488488
providers.reachable_non_generics = reachable_non_generics_provider;
489489
providers.is_reachable_non_generic = is_reachable_non_generic_provider_local;
490490
providers.exported_symbols = exported_symbols_provider_local;
@@ -525,7 +525,7 @@ fn symbol_export_level(tcx: TyCtxt<'_>, sym_def_id: DefId) -> SymbolExportLevel
525525
}
526526

527527
/// This is the symbol name of the given instance instantiated in a specific crate.
528-
pub fn symbol_name_for_instance_in_crate<'tcx>(
528+
pub(crate) fn symbol_name_for_instance_in_crate<'tcx>(
529529
tcx: TyCtxt<'tcx>,
530530
symbol: ExportedSymbol<'tcx>,
531531
instantiating_crate: CrateNum,
@@ -582,7 +582,7 @@ pub fn symbol_name_for_instance_in_crate<'tcx>(
582582
/// This is the symbol name of the given instance as seen by the linker.
583583
///
584584
/// On 32-bit Windows symbols are decorated according to their calling conventions.
585-
pub fn linking_symbol_name_for_instance_in_crate<'tcx>(
585+
pub(crate) fn linking_symbol_name_for_instance_in_crate<'tcx>(
586586
tcx: TyCtxt<'tcx>,
587587
symbol: ExportedSymbol<'tcx>,
588588
instantiating_crate: CrateNum,
@@ -661,7 +661,7 @@ pub fn linking_symbol_name_for_instance_in_crate<'tcx>(
661661
format!("{prefix}{undecorated}{suffix}{args_in_bytes}")
662662
}
663663

664-
pub fn exporting_symbol_name_for_instance_in_crate<'tcx>(
664+
pub(crate) fn exporting_symbol_name_for_instance_in_crate<'tcx>(
665665
tcx: TyCtxt<'tcx>,
666666
symbol: ExportedSymbol<'tcx>,
667667
cnum: CrateNum,

0 commit comments

Comments
 (0)