Skip to content

Commit 43c4999

Browse files
authored
Merge pull request #2841 from hi-rustin/rustin-patch-src
Make all src functions and structs crate-private
2 parents 6244396 + 8d61aa3 commit 43c4999

File tree

11 files changed

+71
-72
lines changed

11 files changed

+71
-72
lines changed

src/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pub mod log;
44
pub mod common;
55
mod download_tracker;
66
pub mod errors;
7-
pub mod help;
7+
mod help;
88
mod job;
99
mod markdown;
1010
pub mod proxy_mode;

src/config.rs

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl<T: Into<String>> From<T> for OverrideFile {
8686
}
8787

8888
#[derive(Debug)]
89-
pub enum OverrideReason {
89+
pub(crate) enum OverrideReason {
9090
Environment,
9191
CommandLine,
9292
OverrideDB(PathBuf),
@@ -170,7 +170,7 @@ pub enum PgpPublicKey {
170170

171171
impl PgpPublicKey {
172172
/// Retrieve the key.
173-
pub fn key(&self) -> &SignedPublicKey {
173+
pub(crate) fn key(&self) -> &SignedPublicKey {
174174
match self {
175175
Self::Builtin => &*BUILTIN_PGP_KEY,
176176
Self::FromEnvironment(_, k) => k,
@@ -179,7 +179,7 @@ impl PgpPublicKey {
179179
}
180180

181181
/// Display the key in detail for the user
182-
pub fn show_key(&self) -> Result<Vec<String>> {
182+
pub(crate) fn show_key(&self) -> Result<Vec<String>> {
183183
fn format_hex(bytes: &[u8], separator: &str, every: usize) -> Result<String> {
184184
use std::fmt::Write;
185185
let mut ret = String::new();
@@ -226,7 +226,7 @@ impl Display for PgpPublicKey {
226226
}
227227
}
228228

229-
pub const UNIX_FALLBACK_SETTINGS: &str = "/etc/rustup/settings.toml";
229+
pub(crate) const UNIX_FALLBACK_SETTINGS: &str = "/etc/rustup/settings.toml";
230230

231231
pub struct Cfg {
232232
profile_override: Option<dist::Profile>,
@@ -241,7 +241,6 @@ pub struct Cfg {
241241
pub toolchain_override: Option<String>,
242242
pub env_override: Option<String>,
243243
pub dist_root_url: String,
244-
pub dist_root_server: String,
245244
pub notify_handler: Arc<dyn Fn(Notification<'_>)>,
246245
}
247246

@@ -330,7 +329,7 @@ impl Cfg {
330329
dist_root_server.as_str(),
331330
Box::new(move |n| (notify_clone)(n.into())),
332331
);
333-
let dist_root = dist_root_server.clone() + "/dist";
332+
let dist_root = dist_root_server + "/dist";
334333

335334
let cfg = Self {
336335
profile_override: None,
@@ -346,7 +345,6 @@ impl Cfg {
346345
toolchain_override: None,
347346
env_override,
348347
dist_root_url: dist_root,
349-
dist_root_server,
350348
};
351349

352350
// Run some basic checks against the constructed configuration
@@ -372,15 +370,15 @@ impl Cfg {
372370
}
373371
}
374372

375-
pub fn get_pgp_keys(&self) -> &[PgpPublicKey] {
373+
pub(crate) fn get_pgp_keys(&self) -> &[PgpPublicKey] {
376374
&self.pgp_keys
377375
}
378376

379377
pub(crate) fn set_profile_override(&mut self, profile: dist::Profile) {
380378
self.profile_override = Some(profile);
381379
}
382380

383-
pub fn set_default(&self, toolchain: &str) -> Result<()> {
381+
pub(crate) fn set_default(&self, toolchain: &str) -> Result<()> {
384382
self.settings_file.with_mut(|s| {
385383
s.default_toolchain = if toolchain == "none" {
386384
None
@@ -393,7 +391,7 @@ impl Cfg {
393391
Ok(())
394392
}
395393

396-
pub fn set_profile(&mut self, profile: &str) -> Result<()> {
394+
pub(crate) fn set_profile(&mut self, profile: &str) -> Result<()> {
397395
match Profile::from_str(profile) {
398396
Ok(p) => {
399397
self.profile_override = None;
@@ -408,7 +406,7 @@ impl Cfg {
408406
}
409407
}
410408

411-
pub fn set_auto_self_update(&mut self, mode: &str) -> Result<()> {
409+
pub(crate) fn set_auto_self_update(&mut self, mode: &str) -> Result<()> {
412410
match SelfUpdateMode::from_str(mode) {
413411
Ok(update_mode) => {
414412
self.settings_file.with_mut(|s| {
@@ -422,7 +420,7 @@ impl Cfg {
422420
}
423421
}
424422

425-
pub fn set_toolchain_override(&mut self, toolchain_override: &str) {
423+
pub(crate) fn set_toolchain_override(&mut self, toolchain_override: &str) {
426424
self.toolchain_override = Some(toolchain_override.to_owned());
427425
}
428426

@@ -446,7 +444,7 @@ impl Cfg {
446444
})
447445
}
448446

449-
pub fn get_self_update_mode(&self) -> Result<SelfUpdateMode> {
447+
pub(crate) fn get_self_update_mode(&self) -> Result<SelfUpdateMode> {
450448
self.settings_file.with(|s| {
451449
let mode = match &s.auto_self_update {
452450
Some(mode) => mode.clone(),
@@ -456,7 +454,7 @@ impl Cfg {
456454
})
457455
}
458456

459-
pub fn get_toolchain(&self, name: &str, create_parent: bool) -> Result<Toolchain<'_>> {
457+
pub(crate) fn get_toolchain(&self, name: &str, create_parent: bool) -> Result<Toolchain<'_>> {
460458
if create_parent {
461459
utils::ensure_dir_exists("toolchains", &self.toolchains_dir, &|n| {
462460
(self.notify_handler)(n)
@@ -466,7 +464,7 @@ impl Cfg {
466464
Toolchain::from(self, name)
467465
}
468466

469-
pub fn get_hash_file(&self, toolchain: &str, create_parent: bool) -> Result<PathBuf> {
467+
pub(crate) fn get_hash_file(&self, toolchain: &str, create_parent: bool) -> Result<PathBuf> {
470468
if create_parent {
471469
utils::ensure_dir_exists(
472470
"update-hash",
@@ -478,7 +476,7 @@ impl Cfg {
478476
Ok(self.update_hash_dir.join(toolchain))
479477
}
480478

481-
pub fn which_binary_by_toolchain(
479+
pub(crate) fn which_binary_by_toolchain(
482480
&self,
483481
toolchain: &str,
484482
binary: &str,
@@ -491,12 +489,12 @@ impl Cfg {
491489
}
492490
}
493491

494-
pub fn which_binary(&self, path: &Path, binary: &str) -> Result<Option<PathBuf>> {
492+
pub(crate) fn which_binary(&self, path: &Path, binary: &str) -> Result<Option<PathBuf>> {
495493
let (toolchain, _) = self.find_or_install_override_toolchain_or_default(path)?;
496494
Ok(Some(toolchain.binary_file(binary)))
497495
}
498496

499-
pub fn upgrade_data(&self) -> Result<()> {
497+
pub(crate) fn upgrade_data(&self) -> Result<()> {
500498
let current_version = self.settings_file.with(|s| Ok(s.version.clone()))?;
501499

502500
if current_version == DEFAULT_METADATA_VERSION {
@@ -536,7 +534,7 @@ impl Cfg {
536534
}
537535
}
538536

539-
pub fn find_default(&self) -> Result<Option<Toolchain<'_>>> {
537+
pub(crate) fn find_default(&self) -> Result<Option<Toolchain<'_>>> {
540538
let opt_name = self.get_default()?;
541539

542540
if let Some(name) = opt_name {
@@ -547,7 +545,10 @@ impl Cfg {
547545
}
548546
}
549547

550-
pub fn find_override(&self, path: &Path) -> Result<Option<(Toolchain<'_>, OverrideReason)>> {
548+
pub(crate) fn find_override(
549+
&self,
550+
path: &Path,
551+
) -> Result<Option<(Toolchain<'_>, OverrideReason)>> {
551552
self.find_override_config(path).map(|opt| {
552553
opt.and_then(|(override_cfg, reason)| {
553554
override_cfg.toolchain.map(|toolchain| (toolchain, reason))
@@ -726,7 +727,7 @@ impl Cfg {
726727
}
727728
}
728729

729-
pub fn find_or_install_override_toolchain_or_default(
730+
pub(crate) fn find_or_install_override_toolchain_or_default(
730731
&self,
731732
path: &Path,
732733
) -> Result<(Toolchain<'_>, Option<OverrideReason>)> {
@@ -823,7 +824,7 @@ impl Cfg {
823824
}
824825
}
825826

826-
pub fn get_default(&self) -> Result<Option<String>> {
827+
pub(crate) fn get_default(&self) -> Result<Option<String>> {
827828
let user_opt = self.settings_file.with(|s| Ok(s.default_toolchain.clone()));
828829
if let Some(fallback_settings) = &self.fallback_settings {
829830
match user_opt {
@@ -834,7 +835,7 @@ impl Cfg {
834835
user_opt
835836
}
836837

837-
pub fn list_toolchains(&self) -> Result<Vec<String>> {
838+
pub(crate) fn list_toolchains(&self) -> Result<Vec<String>> {
838839
if utils::is_directory(&self.toolchains_dir) {
839840
let mut toolchains: Vec<_> = utils::read_dir("toolchains", &self.toolchains_dir)?
840841
.filter_map(io::Result::ok)
@@ -850,7 +851,7 @@ impl Cfg {
850851
}
851852
}
852853

853-
pub fn list_channels(&self) -> Result<Vec<(String, Result<Toolchain<'_>>)>> {
854+
pub(crate) fn list_channels(&self) -> Result<Vec<(String, Result<Toolchain<'_>>)>> {
854855
let toolchains = self.list_toolchains()?;
855856

856857
// Convert the toolchain strings to Toolchain values
@@ -863,7 +864,7 @@ impl Cfg {
863864
.collect())
864865
}
865866

866-
pub fn update_all_channels(
867+
pub(crate) fn update_all_channels(
867868
&self,
868869
force_update: bool,
869870
) -> Result<Vec<(String, Result<UpdateStatus>)>> {
@@ -887,7 +888,7 @@ impl Cfg {
887888
Ok(channels.collect())
888889
}
889890

890-
pub fn check_metadata_version(&self) -> Result<()> {
891+
pub(crate) fn check_metadata_version(&self) -> Result<()> {
891892
utils::assert_is_directory(&self.rustup_dir)?;
892893

893894
self.settings_file.with(|s| {
@@ -902,14 +903,14 @@ impl Cfg {
902903
})
903904
}
904905

905-
pub fn toolchain_for_dir(
906+
pub(crate) fn toolchain_for_dir(
906907
&self,
907908
path: &Path,
908909
) -> Result<(Toolchain<'_>, Option<OverrideReason>)> {
909910
self.find_or_install_override_toolchain_or_default(path)
910911
}
911912

912-
pub fn create_command_for_dir(&self, path: &Path, binary: &str) -> Result<Command> {
913+
pub(crate) fn create_command_for_dir(&self, path: &Path, binary: &str) -> Result<Command> {
913914
let (ref toolchain, _) = self.toolchain_for_dir(path)?;
914915

915916
if let Some(cmd) = self.maybe_do_cargo_fallback(toolchain, binary)? {
@@ -922,7 +923,7 @@ impl Cfg {
922923
}
923924
}
924925

925-
pub fn create_command_for_toolchain(
926+
pub(crate) fn create_command_for_toolchain(
926927
&self,
927928
toolchain: &str,
928929
install_if_missing: bool,
@@ -978,7 +979,7 @@ impl Cfg {
978979
Ok(None)
979980
}
980981

981-
pub fn set_default_host_triple(&self, host_triple: &str) -> Result<()> {
982+
pub(crate) fn set_default_host_triple(&self, host_triple: &str) -> Result<()> {
982983
// Ensure that the provided host_triple is capable of resolving
983984
// against the 'stable' toolchain. This provides early errors
984985
// if the supplied triple is insufficient / bad.
@@ -1001,7 +1002,7 @@ impl Cfg {
10011002
.unwrap_or_else(dist::TargetTriple::from_host_or_build))
10021003
}
10031004

1004-
pub fn resolve_toolchain(&self, name: &str) -> Result<String> {
1005+
pub(crate) fn resolve_toolchain(&self, name: &str) -> Result<String> {
10051006
if let Ok(desc) = dist::PartialToolchainDesc::from_str(name) {
10061007
let host = self.get_default_host_triple()?;
10071008
Ok(desc.resolve(&host)?.to_string())

src/currentprocess.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,13 @@ impl ProcessSource for OSProcess {
191191

192192
#[derive(Clone, Debug, Default)]
193193
pub struct TestProcess {
194-
pub(crate) cwd: PathBuf,
195-
pub(crate) args: Vec<String>,
196-
pub(crate) vars: HashMap<String, String>,
197-
pub(crate) id: u64,
198-
pub(crate) stdin: TestStdinInner,
199-
pub(crate) stdout: TestWriterInner,
200-
pub(crate) stderr: TestWriterInner,
194+
pub cwd: PathBuf,
195+
pub args: Vec<String>,
196+
pub vars: HashMap<String, String>,
197+
pub id: u64,
198+
pub stdin: TestStdinInner,
199+
pub stdout: TestWriterInner,
200+
pub stderr: TestWriterInner,
201201
}
202202

203203
impl TestProcess {

src/env_var.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::process;
77
pub const RUST_RECURSION_COUNT_MAX: u32 = 20;
88

99
#[allow(unused)]
10-
pub fn append_path(name: &str, value: Vec<PathBuf>, cmd: &mut Command) {
10+
fn append_path(name: &str, value: Vec<PathBuf>, cmd: &mut Command) {
1111
let old_value = process().var_os(name);
1212
let mut parts: Vec<PathBuf>;
1313
if let Some(ref v) = old_value {
@@ -21,7 +21,7 @@ pub fn append_path(name: &str, value: Vec<PathBuf>, cmd: &mut Command) {
2121
}
2222
}
2323

24-
pub fn prepend_path(name: &str, value: Vec<PathBuf>, cmd: &mut Command) {
24+
pub(crate) fn prepend_path(name: &str, value: Vec<PathBuf>, cmd: &mut Command) {
2525
let old_value = process().var_os(name);
2626
let mut parts: Vec<PathBuf>;
2727
if let Some(ref v) = old_value {
@@ -36,7 +36,7 @@ pub fn prepend_path(name: &str, value: Vec<PathBuf>, cmd: &mut Command) {
3636
}
3737
}
3838

39-
pub fn inc(name: &str, cmd: &mut Command) {
39+
pub(crate) fn inc(name: &str, cmd: &mut Command) {
4040
let old_value = process()
4141
.var(name)
4242
.ok()

src/errors.rs

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

1111
use crate::dist::manifest::{Component, Manifest};
1212

13-
pub const TOOLSTATE_MSG: &str =
13+
const TOOLSTATE_MSG: &str =
1414
"If you require these components, please install and use the latest successful build version,\n\
1515
which you can find at <https://rust-lang.github.io/rustup-components-history>.\n\nAfter determining \
1616
the correct date, install it with a command such as:\n\n \

src/fallback_settings.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ impl Default for FallbackSettings {
2020
}
2121

2222
impl FallbackSettings {
23-
pub fn new<P: AsRef<Path>>(path: P) -> Result<Option<Self>> {
23+
pub(crate) fn new<P: AsRef<Path>>(path: P) -> Result<Option<Self>> {
2424
// Users cannot fix issues with missing/unreadable/invalid centralised files, but logging isn't setup early so
2525
// we can't simply trap all errors and log diagnostics. Ideally we would, and then separate these into different
2626
// sorts of issues, logging messages about errors that should be fixed. Instead we trap some conservative errors

src/install.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ use crate::dist::prefix::InstallPrefix;
1010
use crate::dist::Notification;
1111
use crate::errors::RustupError;
1212
use crate::notifications::Notification as RootNotification;
13-
use crate::toolchain::{CustomToolchain, DistributableToolchain, Toolchain, UpdateStatus};
13+
use crate::toolchain::{CustomToolchain, Toolchain, UpdateStatus};
1414
use crate::utils::utils;
1515

1616
#[derive(Copy, Clone)]
17-
pub enum InstallMethod<'a> {
17+
pub(crate) enum InstallMethod<'a> {
1818
Copy(&'a Path, &'a CustomToolchain<'a>),
1919
Link(&'a Path, &'a CustomToolchain<'a>),
2020
// bool is whether to force an update
@@ -35,13 +35,12 @@ pub enum InstallMethod<'a> {
3535
components: &'a [&'a str],
3636
// Extra targets to install from dist
3737
targets: &'a [&'a str],
38-
distributable: &'a DistributableToolchain<'a>,
3938
},
4039
}
4140

4241
impl<'a> InstallMethod<'a> {
4342
// Install a toolchain
44-
pub fn install(&self, toolchain: &Toolchain<'a>) -> Result<UpdateStatus> {
43+
pub(crate) fn install(&self, toolchain: &Toolchain<'a>) -> Result<UpdateStatus> {
4544
let previous_version = if toolchain.exists() {
4645
Some(toolchain.rustc_version())
4746
} else {

0 commit comments

Comments
 (0)