diff --git a/src/cli.rs b/src/cli.rs index 163fbd993d..7ac235724c 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -4,7 +4,7 @@ pub mod log; pub mod common; mod download_tracker; pub mod errors; -pub mod help; +mod help; mod job; mod markdown; pub mod proxy_mode; diff --git a/src/config.rs b/src/config.rs index b91b94d21e..ab38e037fc 100644 --- a/src/config.rs +++ b/src/config.rs @@ -86,7 +86,7 @@ impl> From for OverrideFile { } #[derive(Debug)] -pub enum OverrideReason { +pub(crate) enum OverrideReason { Environment, CommandLine, OverrideDB(PathBuf), @@ -170,7 +170,7 @@ pub enum PgpPublicKey { impl PgpPublicKey { /// Retrieve the key. - pub fn key(&self) -> &SignedPublicKey { + pub(crate) fn key(&self) -> &SignedPublicKey { match self { Self::Builtin => &*BUILTIN_PGP_KEY, Self::FromEnvironment(_, k) => k, @@ -179,7 +179,7 @@ impl PgpPublicKey { } /// Display the key in detail for the user - pub fn show_key(&self) -> Result> { + pub(crate) fn show_key(&self) -> Result> { fn format_hex(bytes: &[u8], separator: &str, every: usize) -> Result { use std::fmt::Write; let mut ret = String::new(); @@ -226,7 +226,7 @@ impl Display for PgpPublicKey { } } -pub const UNIX_FALLBACK_SETTINGS: &str = "/etc/rustup/settings.toml"; +pub(crate) const UNIX_FALLBACK_SETTINGS: &str = "/etc/rustup/settings.toml"; pub struct Cfg { profile_override: Option, @@ -241,7 +241,6 @@ pub struct Cfg { pub toolchain_override: Option, pub env_override: Option, pub dist_root_url: String, - pub dist_root_server: String, pub notify_handler: Arc)>, } @@ -330,7 +329,7 @@ impl Cfg { dist_root_server.as_str(), Box::new(move |n| (notify_clone)(n.into())), ); - let dist_root = dist_root_server.clone() + "/dist"; + let dist_root = dist_root_server + "/dist"; let cfg = Self { profile_override: None, @@ -346,7 +345,6 @@ impl Cfg { toolchain_override: None, env_override, dist_root_url: dist_root, - dist_root_server, }; // Run some basic checks against the constructed configuration @@ -372,7 +370,7 @@ impl Cfg { } } - pub fn get_pgp_keys(&self) -> &[PgpPublicKey] { + pub(crate) fn get_pgp_keys(&self) -> &[PgpPublicKey] { &self.pgp_keys } @@ -380,7 +378,7 @@ impl Cfg { self.profile_override = Some(profile); } - pub fn set_default(&self, toolchain: &str) -> Result<()> { + pub(crate) fn set_default(&self, toolchain: &str) -> Result<()> { self.settings_file.with_mut(|s| { s.default_toolchain = Some(toolchain.to_owned()); Ok(()) @@ -389,7 +387,7 @@ impl Cfg { Ok(()) } - pub fn set_profile(&mut self, profile: &str) -> Result<()> { + pub(crate) fn set_profile(&mut self, profile: &str) -> Result<()> { match Profile::from_str(profile) { Ok(p) => { self.profile_override = None; @@ -404,7 +402,7 @@ impl Cfg { } } - pub fn set_auto_self_update(&mut self, mode: &str) -> Result<()> { + pub(crate) fn set_auto_self_update(&mut self, mode: &str) -> Result<()> { match SelfUpdateMode::from_str(mode) { Ok(update_mode) => { self.settings_file.with_mut(|s| { @@ -418,7 +416,7 @@ impl Cfg { } } - pub fn set_toolchain_override(&mut self, toolchain_override: &str) { + pub(crate) fn set_toolchain_override(&mut self, toolchain_override: &str) { self.toolchain_override = Some(toolchain_override.to_owned()); } @@ -442,7 +440,7 @@ impl Cfg { }) } - pub fn get_self_update_mode(&self) -> Result { + pub(crate) fn get_self_update_mode(&self) -> Result { self.settings_file.with(|s| { let mode = match &s.auto_self_update { Some(mode) => mode.clone(), @@ -452,7 +450,7 @@ impl Cfg { }) } - pub fn get_toolchain(&self, name: &str, create_parent: bool) -> Result> { + pub(crate) fn get_toolchain(&self, name: &str, create_parent: bool) -> Result> { if create_parent { utils::ensure_dir_exists("toolchains", &self.toolchains_dir, &|n| { (self.notify_handler)(n) @@ -462,7 +460,7 @@ impl Cfg { Toolchain::from(self, name) } - pub fn get_hash_file(&self, toolchain: &str, create_parent: bool) -> Result { + pub(crate) fn get_hash_file(&self, toolchain: &str, create_parent: bool) -> Result { if create_parent { utils::ensure_dir_exists( "update-hash", @@ -474,7 +472,7 @@ impl Cfg { Ok(self.update_hash_dir.join(toolchain)) } - pub fn which_binary_by_toolchain( + pub(crate) fn which_binary_by_toolchain( &self, toolchain: &str, binary: &str, @@ -487,12 +485,12 @@ impl Cfg { } } - pub fn which_binary(&self, path: &Path, binary: &str) -> Result> { + pub(crate) fn which_binary(&self, path: &Path, binary: &str) -> Result> { let (toolchain, _) = self.find_or_install_override_toolchain_or_default(path)?; Ok(Some(toolchain.binary_file(binary))) } - pub fn upgrade_data(&self) -> Result<()> { + pub(crate) fn upgrade_data(&self) -> Result<()> { let current_version = self.settings_file.with(|s| Ok(s.version.clone()))?; if current_version == DEFAULT_METADATA_VERSION { @@ -532,7 +530,7 @@ impl Cfg { } } - pub fn find_default(&self) -> Result>> { + pub(crate) fn find_default(&self) -> Result>> { let opt_name = self.get_default()?; if let Some(name) = opt_name { @@ -543,7 +541,10 @@ impl Cfg { } } - pub fn find_override(&self, path: &Path) -> Result, OverrideReason)>> { + pub(crate) fn find_override( + &self, + path: &Path, + ) -> Result, OverrideReason)>> { self.find_override_config(path).map(|opt| { opt.and_then(|(override_cfg, reason)| { override_cfg.toolchain.map(|toolchain| (toolchain, reason)) @@ -722,7 +723,7 @@ impl Cfg { } } - pub fn find_or_install_override_toolchain_or_default( + pub(crate) fn find_or_install_override_toolchain_or_default( &self, path: &Path, ) -> Result<(Toolchain<'_>, Option)> { @@ -819,7 +820,7 @@ impl Cfg { } } - pub fn get_default(&self) -> Result> { + pub(crate) fn get_default(&self) -> Result> { let user_opt = self.settings_file.with(|s| Ok(s.default_toolchain.clone())); if let Some(fallback_settings) = &self.fallback_settings { match user_opt { @@ -830,7 +831,7 @@ impl Cfg { user_opt } - pub fn list_toolchains(&self) -> Result> { + pub(crate) fn list_toolchains(&self) -> Result> { if utils::is_directory(&self.toolchains_dir) { let mut toolchains: Vec<_> = utils::read_dir("toolchains", &self.toolchains_dir)? .filter_map(io::Result::ok) @@ -846,7 +847,7 @@ impl Cfg { } } - pub fn list_channels(&self) -> Result>)>> { + pub(crate) fn list_channels(&self) -> Result>)>> { let toolchains = self.list_toolchains()?; // Convert the toolchain strings to Toolchain values @@ -859,7 +860,7 @@ impl Cfg { .collect()) } - pub fn update_all_channels( + pub(crate) fn update_all_channels( &self, force_update: bool, ) -> Result)>> { @@ -883,7 +884,7 @@ impl Cfg { Ok(channels.collect()) } - pub fn check_metadata_version(&self) -> Result<()> { + pub(crate) fn check_metadata_version(&self) -> Result<()> { utils::assert_is_directory(&self.rustup_dir)?; self.settings_file.with(|s| { @@ -898,14 +899,14 @@ impl Cfg { }) } - pub fn toolchain_for_dir( + pub(crate) fn toolchain_for_dir( &self, path: &Path, ) -> Result<(Toolchain<'_>, Option)> { self.find_or_install_override_toolchain_or_default(path) } - pub fn create_command_for_dir(&self, path: &Path, binary: &str) -> Result { + pub(crate) fn create_command_for_dir(&self, path: &Path, binary: &str) -> Result { let (ref toolchain, _) = self.toolchain_for_dir(path)?; if let Some(cmd) = self.maybe_do_cargo_fallback(toolchain, binary)? { @@ -918,7 +919,7 @@ impl Cfg { } } - pub fn create_command_for_toolchain( + pub(crate) fn create_command_for_toolchain( &self, toolchain: &str, install_if_missing: bool, @@ -974,7 +975,7 @@ impl Cfg { Ok(None) } - pub fn set_default_host_triple(&self, host_triple: &str) -> Result<()> { + pub(crate) fn set_default_host_triple(&self, host_triple: &str) -> Result<()> { // Ensure that the provided host_triple is capable of resolving // against the 'stable' toolchain. This provides early errors // if the supplied triple is insufficient / bad. @@ -997,7 +998,7 @@ impl Cfg { .unwrap_or_else(dist::TargetTriple::from_host_or_build)) } - pub fn resolve_toolchain(&self, name: &str) -> Result { + pub(crate) fn resolve_toolchain(&self, name: &str) -> Result { if let Ok(desc) = dist::PartialToolchainDesc::from_str(name) { let host = self.get_default_host_triple()?; Ok(desc.resolve(&host)?.to_string()) diff --git a/src/currentprocess.rs b/src/currentprocess.rs index c286f9a5df..6e53145435 100644 --- a/src/currentprocess.rs +++ b/src/currentprocess.rs @@ -191,13 +191,13 @@ impl ProcessSource for OSProcess { #[derive(Clone, Debug, Default)] pub struct TestProcess { - pub(crate) cwd: PathBuf, - pub(crate) args: Vec, - pub(crate) vars: HashMap, - pub(crate) id: u64, - pub(crate) stdin: TestStdinInner, - pub(crate) stdout: TestWriterInner, - pub(crate) stderr: TestWriterInner, + pub cwd: PathBuf, + pub args: Vec, + pub vars: HashMap, + pub id: u64, + pub stdin: TestStdinInner, + pub stdout: TestWriterInner, + pub stderr: TestWriterInner, } impl TestProcess { diff --git a/src/env_var.rs b/src/env_var.rs index ebc7d81bc5..ae9670ae4b 100644 --- a/src/env_var.rs +++ b/src/env_var.rs @@ -7,7 +7,7 @@ use crate::process; pub const RUST_RECURSION_COUNT_MAX: u32 = 20; #[allow(unused)] -pub fn append_path(name: &str, value: Vec, cmd: &mut Command) { +fn append_path(name: &str, value: Vec, cmd: &mut Command) { let old_value = process().var_os(name); let mut parts: Vec; if let Some(ref v) = old_value { @@ -21,7 +21,7 @@ pub fn append_path(name: &str, value: Vec, cmd: &mut Command) { } } -pub fn prepend_path(name: &str, value: Vec, cmd: &mut Command) { +pub(crate) fn prepend_path(name: &str, value: Vec, cmd: &mut Command) { let old_value = process().var_os(name); let mut parts: Vec; if let Some(ref v) = old_value { @@ -36,7 +36,7 @@ pub fn prepend_path(name: &str, value: Vec, cmd: &mut Command) { } } -pub fn inc(name: &str, cmd: &mut Command) { +pub(crate) fn inc(name: &str, cmd: &mut Command) { let old_value = process() .var(name) .ok() diff --git a/src/errors.rs b/src/errors.rs index 5b20ddd722..3e190ff2b2 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -10,7 +10,7 @@ use url::Url; use crate::dist::manifest::{Component, Manifest}; -pub const TOOLSTATE_MSG: &str = +const TOOLSTATE_MSG: &str = "If you require these components, please install and use the latest successful build version,\n\ which you can find at .\n\nAfter determining \ the correct date, install it with a command such as:\n\n \ diff --git a/src/fallback_settings.rs b/src/fallback_settings.rs index 54ca0bf568..9a07055b9b 100644 --- a/src/fallback_settings.rs +++ b/src/fallback_settings.rs @@ -20,7 +20,7 @@ impl Default for FallbackSettings { } impl FallbackSettings { - pub fn new>(path: P) -> Result> { + pub(crate) fn new>(path: P) -> Result> { // Users cannot fix issues with missing/unreadable/invalid centralised files, but logging isn't setup early so // we can't simply trap all errors and log diagnostics. Ideally we would, and then separate these into different // sorts of issues, logging messages about errors that should be fixed. Instead we trap some conservative errors diff --git a/src/install.rs b/src/install.rs index 4f4958985e..6cc9345208 100644 --- a/src/install.rs +++ b/src/install.rs @@ -10,11 +10,11 @@ use crate::dist::prefix::InstallPrefix; use crate::dist::Notification; use crate::errors::RustupError; use crate::notifications::Notification as RootNotification; -use crate::toolchain::{CustomToolchain, DistributableToolchain, Toolchain, UpdateStatus}; +use crate::toolchain::{CustomToolchain, Toolchain, UpdateStatus}; use crate::utils::utils; #[derive(Copy, Clone)] -pub enum InstallMethod<'a> { +pub(crate) enum InstallMethod<'a> { Copy(&'a Path, &'a CustomToolchain<'a>), Link(&'a Path, &'a CustomToolchain<'a>), // bool is whether to force an update @@ -35,13 +35,12 @@ pub enum InstallMethod<'a> { components: &'a [&'a str], // Extra targets to install from dist targets: &'a [&'a str], - distributable: &'a DistributableToolchain<'a>, }, } impl<'a> InstallMethod<'a> { // Install a toolchain - pub fn install(&self, toolchain: &Toolchain<'a>) -> Result { + pub(crate) fn install(&self, toolchain: &Toolchain<'a>) -> Result { let previous_version = if toolchain.exists() { Some(toolchain.rustc_version()) } else { diff --git a/src/lib.rs b/src/lib.rs index aa47f6b80d..ee03f79584 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,11 +8,10 @@ #![recursion_limit = "1024"] pub use crate::config::*; -pub use crate::currentprocess::varsource::*; -pub use crate::currentprocess::*; +use crate::currentprocess::*; pub use crate::errors::*; pub use crate::notifications::*; -pub use crate::toolchain::*; +use crate::toolchain::*; pub(crate) use crate::utils::toml_utils; #[macro_use] @@ -60,17 +59,17 @@ fn component_for_bin(binary: &str) -> Option<&'static str> { #[macro_use] pub mod cli; -pub mod command; +mod command; mod config; pub mod currentprocess; -pub mod diskio; +mod diskio; pub mod dist; pub mod env_var; pub mod errors; -pub mod fallback_settings; +mod fallback_settings; mod install; -mod notifications; -pub mod settings; +pub mod notifications; +mod settings; pub mod test; -pub mod toolchain; +mod toolchain; pub mod utils; diff --git a/src/settings.rs b/src/settings.rs index c0197fee51..af70d21396 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -12,8 +12,8 @@ use crate::notifications::*; use crate::toml_utils::*; use crate::utils::utils; -pub const SUPPORTED_METADATA_VERSIONS: [&str; 2] = ["2", "12"]; -pub const DEFAULT_METADATA_VERSION: &str = "12"; +pub(crate) const SUPPORTED_METADATA_VERSIONS: [&str; 2] = ["2", "12"]; +pub(crate) const DEFAULT_METADATA_VERSION: &str = "12"; #[derive(Clone, Debug, PartialEq)] pub struct SettingsFile { @@ -22,7 +22,7 @@ pub struct SettingsFile { } impl SettingsFile { - pub fn new(path: PathBuf) -> Self { + pub(crate) fn new(path: PathBuf) -> Self { Self { path, cache: RefCell::new(None), @@ -55,14 +55,14 @@ impl SettingsFile { Ok(()) } - pub fn with Result>(&self, f: F) -> Result { + pub(crate) fn with Result>(&self, f: F) -> Result { self.read_settings()?; // Settings can no longer be None so it's OK to unwrap f(self.cache.borrow().as_ref().unwrap()) } - pub fn with_mut Result>(&self, f: F) -> Result { + pub(crate) fn with_mut Result>(&self, f: F) -> Result { self.read_settings()?; // Settings can no longer be None so it's OK to unwrap @@ -137,16 +137,16 @@ impl Settings { self.overrides.get(&key).cloned() } - pub fn parse(data: &str) -> Result { + pub(crate) fn parse(data: &str) -> Result { let value = toml::from_str(data).context("error parsing settings")?; Self::from_toml(value, "") } - pub fn stringify(self) -> String { + pub(crate) fn stringify(self) -> String { toml::Value::Table(self.into_toml()).to_string() } - pub fn from_toml(mut table: toml::value::Table, path: &str) -> Result { + pub(crate) fn from_toml(mut table: toml::value::Table, path: &str) -> Result { let version = get_string(&mut table, "version", path)?; if !SUPPORTED_METADATA_VERSIONS.contains(&&*version) { return Err(RustupError::UnknownMetadataVersion(version).into()); @@ -165,7 +165,7 @@ impl Settings { auto_self_update, }) } - pub fn into_toml(self) -> toml::value::Table { + pub(crate) fn into_toml(self) -> toml::value::Table { let mut result = toml::value::Table::new(); result.insert("version".to_owned(), toml::Value::String(self.version)); diff --git a/src/test.rs b/src/test.rs index 219b4dcb9f..dcd8b8850d 100644 --- a/src/test.rs +++ b/src/test.rs @@ -8,6 +8,7 @@ use std::io; use std::path::{Path, PathBuf}; use std::process::Command; +#[cfg(test)] use anyhow::Result; pub use crate::cli::self_update::test::{get_path, with_saved_path}; @@ -168,7 +169,8 @@ impl fmt::Display for RustupHome { /// Create an isolated rustup home with no content, then call f with it, and /// delete it afterwards. -pub fn with_rustup_home(f: F) -> Result<()> +#[cfg(test)] +pub(crate) fn with_rustup_home(f: F) -> Result<()> where F: FnOnce(&RustupHome) -> Result<()>, { diff --git a/src/toolchain.rs b/src/toolchain.rs index a9963a83b6..b76a3cd22d 100644 --- a/src/toolchain.rs +++ b/src/toolchain.rs @@ -67,7 +67,7 @@ pub enum UpdateStatus { static V1_COMMON_COMPONENT_LIST: &[&str] = &["cargo", "rustc", "rust-docs"]; impl<'a> Toolchain<'a> { - pub fn from(cfg: &'a Cfg, name: &str) -> Result { + pub(crate) fn from(cfg: &'a Cfg, name: &str) -> Result { let resolved_name = cfg.resolve_toolchain(name)?; let path = cfg.toolchains_dir.join(&resolved_name); Ok(Toolchain { @@ -78,7 +78,7 @@ impl<'a> Toolchain<'a> { }) } - pub fn from_path( + pub(crate) fn from_path( cfg: &'a Cfg, cfg_file: Option>, path: impl AsRef, @@ -127,7 +127,7 @@ impl<'a> Toolchain<'a> { Ok(Box::new(toolchain) as Box>) } } - pub fn cfg(&self) -> &Cfg { + pub(crate) fn cfg(&self) -> &Cfg { self.cfg } pub fn name(&self) -> &str { @@ -774,7 +774,6 @@ impl<'a> DistributableToolchain<'a> { old_date: old_date.as_deref(), components, targets, - distributable: self, } .install(self.0) } @@ -795,7 +794,6 @@ impl<'a> DistributableToolchain<'a> { old_date: None, components: &[], targets: &[], - distributable: self, } .install(self.0)?) } else {