Skip to content

Make all src functions and structs crate-private #2841

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
63 changes: 32 additions & 31 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl<T: Into<String>> From<T> for OverrideFile {
}

#[derive(Debug)]
pub enum OverrideReason {
pub(crate) enum OverrideReason {
Environment,
CommandLine,
OverrideDB(PathBuf),
Expand Down Expand Up @@ -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,
Expand All @@ -179,7 +179,7 @@ impl PgpPublicKey {
}

/// Display the key in detail for the user
pub fn show_key(&self) -> Result<Vec<String>> {
pub(crate) fn show_key(&self) -> Result<Vec<String>> {
fn format_hex(bytes: &[u8], separator: &str, every: usize) -> Result<String> {
use std::fmt::Write;
let mut ret = String::new();
Expand Down Expand Up @@ -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<dist::Profile>,
Expand All @@ -241,7 +241,6 @@ pub struct Cfg {
pub toolchain_override: Option<String>,
pub env_override: Option<String>,
pub dist_root_url: String,
pub dist_root_server: String,
pub notify_handler: Arc<dyn Fn(Notification<'_>)>,
}

Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand All @@ -372,15 +370,15 @@ impl Cfg {
}
}

pub fn get_pgp_keys(&self) -> &[PgpPublicKey] {
pub(crate) fn get_pgp_keys(&self) -> &[PgpPublicKey] {
&self.pgp_keys
}

pub(crate) fn set_profile_override(&mut self, profile: dist::Profile) {
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(())
Expand All @@ -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;
Expand All @@ -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| {
Expand All @@ -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());
}

Expand All @@ -442,7 +440,7 @@ impl Cfg {
})
}

pub fn get_self_update_mode(&self) -> Result<SelfUpdateMode> {
pub(crate) fn get_self_update_mode(&self) -> Result<SelfUpdateMode> {
self.settings_file.with(|s| {
let mode = match &s.auto_self_update {
Some(mode) => mode.clone(),
Expand All @@ -452,7 +450,7 @@ impl Cfg {
})
}

pub fn get_toolchain(&self, name: &str, create_parent: bool) -> Result<Toolchain<'_>> {
pub(crate) fn get_toolchain(&self, name: &str, create_parent: bool) -> Result<Toolchain<'_>> {
if create_parent {
utils::ensure_dir_exists("toolchains", &self.toolchains_dir, &|n| {
(self.notify_handler)(n)
Expand All @@ -462,7 +460,7 @@ impl Cfg {
Toolchain::from(self, name)
}

pub fn get_hash_file(&self, toolchain: &str, create_parent: bool) -> Result<PathBuf> {
pub(crate) fn get_hash_file(&self, toolchain: &str, create_parent: bool) -> Result<PathBuf> {
if create_parent {
utils::ensure_dir_exists(
"update-hash",
Expand All @@ -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,
Expand All @@ -487,12 +485,12 @@ impl Cfg {
}
}

pub fn which_binary(&self, path: &Path, binary: &str) -> Result<Option<PathBuf>> {
pub(crate) fn which_binary(&self, path: &Path, binary: &str) -> Result<Option<PathBuf>> {
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 {
Expand Down Expand Up @@ -532,7 +530,7 @@ impl Cfg {
}
}

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

if let Some(name) = opt_name {
Expand All @@ -543,7 +541,10 @@ impl Cfg {
}
}

pub fn find_override(&self, path: &Path) -> Result<Option<(Toolchain<'_>, OverrideReason)>> {
pub(crate) fn find_override(
&self,
path: &Path,
) -> Result<Option<(Toolchain<'_>, OverrideReason)>> {
self.find_override_config(path).map(|opt| {
opt.and_then(|(override_cfg, reason)| {
override_cfg.toolchain.map(|toolchain| (toolchain, reason))
Expand Down Expand Up @@ -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<OverrideReason>)> {
Expand Down Expand Up @@ -819,7 +820,7 @@ impl Cfg {
}
}

pub fn get_default(&self) -> Result<Option<String>> {
pub(crate) fn get_default(&self) -> Result<Option<String>> {
let user_opt = self.settings_file.with(|s| Ok(s.default_toolchain.clone()));
if let Some(fallback_settings) = &self.fallback_settings {
match user_opt {
Expand All @@ -830,7 +831,7 @@ impl Cfg {
user_opt
}

pub fn list_toolchains(&self) -> Result<Vec<String>> {
pub(crate) fn list_toolchains(&self) -> Result<Vec<String>> {
if utils::is_directory(&self.toolchains_dir) {
let mut toolchains: Vec<_> = utils::read_dir("toolchains", &self.toolchains_dir)?
.filter_map(io::Result::ok)
Expand All @@ -846,7 +847,7 @@ impl Cfg {
}
}

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

// Convert the toolchain strings to Toolchain values
Expand All @@ -859,7 +860,7 @@ impl Cfg {
.collect())
}

pub fn update_all_channels(
pub(crate) fn update_all_channels(
&self,
force_update: bool,
) -> Result<Vec<(String, Result<UpdateStatus>)>> {
Expand All @@ -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| {
Expand All @@ -898,14 +899,14 @@ impl Cfg {
})
}

pub fn toolchain_for_dir(
pub(crate) fn toolchain_for_dir(
&self,
path: &Path,
) -> Result<(Toolchain<'_>, Option<OverrideReason>)> {
self.find_or_install_override_toolchain_or_default(path)
}

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

if let Some(cmd) = self.maybe_do_cargo_fallback(toolchain, binary)? {
Expand All @@ -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,
Expand Down Expand Up @@ -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.
Expand All @@ -997,7 +998,7 @@ impl Cfg {
.unwrap_or_else(dist::TargetTriple::from_host_or_build))
}

pub fn resolve_toolchain(&self, name: &str) -> Result<String> {
pub(crate) fn resolve_toolchain(&self, name: &str) -> Result<String> {
if let Ok(desc) = dist::PartialToolchainDesc::from_str(name) {
let host = self.get_default_host_triple()?;
Ok(desc.resolve(&host)?.to_string())
Expand Down
14 changes: 7 additions & 7 deletions src/currentprocess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,13 @@ impl ProcessSource for OSProcess {

#[derive(Clone, Debug, Default)]
pub struct TestProcess {
pub(crate) cwd: PathBuf,
pub(crate) args: Vec<String>,
pub(crate) vars: HashMap<String, String>,
pub(crate) id: u64,
pub(crate) stdin: TestStdinInner,
pub(crate) stdout: TestWriterInner,
pub(crate) stderr: TestWriterInner,
pub cwd: PathBuf,
pub args: Vec<String>,
pub vars: HashMap<String, String>,
pub id: u64,
pub stdin: TestStdinInner,
pub stdout: TestWriterInner,
pub stderr: TestWriterInner,
}

impl TestProcess {
Expand Down
6 changes: 3 additions & 3 deletions src/env_var.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf>, cmd: &mut Command) {
fn append_path(name: &str, value: Vec<PathBuf>, cmd: &mut Command) {
let old_value = process().var_os(name);
let mut parts: Vec<PathBuf>;
if let Some(ref v) = old_value {
Expand All @@ -21,7 +21,7 @@ pub fn append_path(name: &str, value: Vec<PathBuf>, cmd: &mut Command) {
}
}

pub fn prepend_path(name: &str, value: Vec<PathBuf>, cmd: &mut Command) {
pub(crate) fn prepend_path(name: &str, value: Vec<PathBuf>, cmd: &mut Command) {
let old_value = process().var_os(name);
let mut parts: Vec<PathBuf>;
if let Some(ref v) = old_value {
Expand All @@ -36,7 +36,7 @@ pub fn prepend_path(name: &str, value: Vec<PathBuf>, 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()
Expand Down
2 changes: 1 addition & 1 deletion src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://rust-lang.github.io/rustup-components-history>.\n\nAfter determining \
the correct date, install it with a command such as:\n\n \
Expand Down
2 changes: 1 addition & 1 deletion src/fallback_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl Default for FallbackSettings {
}

impl FallbackSettings {
pub fn new<P: AsRef<Path>>(path: P) -> Result<Option<Self>> {
pub(crate) fn new<P: AsRef<Path>>(path: P) -> Result<Option<Self>> {
// 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
Expand Down
7 changes: 3 additions & 4 deletions src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<UpdateStatus> {
pub(crate) fn install(&self, toolchain: &Toolchain<'a>) -> Result<UpdateStatus> {
let previous_version = if toolchain.exists() {
Some(toolchain.rustc_version())
} else {
Expand Down
Loading