Skip to content

Commit 31a98d3

Browse files
authored
Merge pull request #2787 from hi-rustin/rustin-patch-utils-cleanup
Make all utils functions and structs crate-private and cleanup unused functions
2 parents a45e4cd + b9e2eb6 commit 31a98d3

23 files changed

+136
-155
lines changed

src/cli/common.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ fn show_channel_updates(cfg: &Cfg, toolchains: Vec<(String, Result<UpdateStatus>
249249
Ok(())
250250
}
251251

252-
pub fn update_all_channels(
252+
pub(crate) fn update_all_channels(
253253
cfg: &Cfg,
254254
do_self_update: bool,
255255
force_update: bool,
@@ -327,7 +327,7 @@ pub fn self_update_permitted(explicit: bool) -> Result<SelfUpdatePermission> {
327327
}
328328
}
329329

330-
pub fn self_update<F>(before_restart: F) -> Result<utils::ExitCode>
330+
pub(crate) fn self_update<F>(before_restart: F) -> Result<utils::ExitCode>
331331
where
332332
F: FnOnce() -> Result<utils::ExitCode>,
333333
{
@@ -354,7 +354,7 @@ where
354354
Ok(utils::ExitCode(0))
355355
}
356356

357-
pub fn list_targets(toolchain: &Toolchain<'_>) -> Result<utils::ExitCode> {
357+
pub(crate) fn list_targets(toolchain: &Toolchain<'_>) -> Result<utils::ExitCode> {
358358
let mut t = term2::stdout();
359359
let distributable = DistributableToolchain::new_for_components(&toolchain)?;
360360
let components = distributable.list_components()?;
@@ -378,7 +378,7 @@ pub fn list_targets(toolchain: &Toolchain<'_>) -> Result<utils::ExitCode> {
378378
Ok(utils::ExitCode(0))
379379
}
380380

381-
pub fn list_installed_targets(toolchain: &Toolchain<'_>) -> Result<utils::ExitCode> {
381+
pub(crate) fn list_installed_targets(toolchain: &Toolchain<'_>) -> Result<utils::ExitCode> {
382382
let mut t = term2::stdout();
383383
let distributable = DistributableToolchain::new_for_components(&toolchain)?;
384384
let components = distributable.list_components()?;
@@ -397,7 +397,7 @@ pub fn list_installed_targets(toolchain: &Toolchain<'_>) -> Result<utils::ExitCo
397397
Ok(utils::ExitCode(0))
398398
}
399399

400-
pub fn list_components(toolchain: &Toolchain<'_>) -> Result<utils::ExitCode> {
400+
pub(crate) fn list_components(toolchain: &Toolchain<'_>) -> Result<utils::ExitCode> {
401401
let mut t = term2::stdout();
402402
let distributable = DistributableToolchain::new_for_components(&toolchain)?;
403403
let components = distributable.list_components()?;
@@ -415,7 +415,7 @@ pub fn list_components(toolchain: &Toolchain<'_>) -> Result<utils::ExitCode> {
415415
Ok(utils::ExitCode(0))
416416
}
417417

418-
pub fn list_installed_components(toolchain: &Toolchain<'_>) -> Result<utils::ExitCode> {
418+
pub(crate) fn list_installed_components(toolchain: &Toolchain<'_>) -> Result<utils::ExitCode> {
419419
let mut t = term2::stdout();
420420
let distributable = DistributableToolchain::new_for_components(&toolchain)?;
421421
let components = distributable.list_components()?;
@@ -460,7 +460,7 @@ fn print_toolchain_path(
460460
Ok(())
461461
}
462462

463-
pub fn list_toolchains(cfg: &Cfg, verbose: bool) -> Result<utils::ExitCode> {
463+
pub(crate) fn list_toolchains(cfg: &Cfg, verbose: bool) -> Result<utils::ExitCode> {
464464
let toolchains = cfg.list_toolchains()?;
465465
if toolchains.is_empty() {
466466
writeln!(process().stdout(), "no installed toolchains")?;
@@ -495,7 +495,7 @@ pub fn list_toolchains(cfg: &Cfg, verbose: bool) -> Result<utils::ExitCode> {
495495
Ok(utils::ExitCode(0))
496496
}
497497

498-
pub fn list_overrides(cfg: &Cfg) -> Result<utils::ExitCode> {
498+
pub(crate) fn list_overrides(cfg: &Cfg) -> Result<utils::ExitCode> {
499499
let overrides = cfg.settings_file.with(|s| Ok(s.overrides.clone()))?;
500500

501501
if overrides.is_empty() {
@@ -538,7 +538,7 @@ pub fn version() -> &'static str {
538538
&RENDERED
539539
}
540540

541-
pub fn dump_testament() -> Result<utils::ExitCode> {
541+
pub(crate) fn dump_testament() -> Result<utils::ExitCode> {
542542
use git_testament::GitModification::*;
543543
writeln!(
544544
process().stdout(),

src/cli/download_tracker.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl DownloadTracker {
7373
self
7474
}
7575

76-
pub fn handle_notification(&mut self, n: &Notification<'_>) -> bool {
76+
pub(crate) fn handle_notification(&mut self, n: &Notification<'_>) -> bool {
7777
match *n {
7878
Notification::Install(In::Utils(Un::DownloadContentLengthReceived(content_len))) => {
7979
self.content_length_received(content_len);
@@ -219,7 +219,7 @@ impl DownloadTracker {
219219
}
220220
}
221221

222-
pub fn push_unit(&mut self, new_unit: Unit) {
222+
pub(crate) fn push_unit(&mut self, new_unit: Unit) {
223223
self.units.push(new_unit);
224224
}
225225

src/cli/self_update.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ use crate::utils::Notification;
7070
use crate::{Cfg, UpdateStatus};
7171
use crate::{DUP_TOOLS, TOOLS};
7272
use os::*;
73-
pub use os::{delete_rustup_and_cargo_home, run_update, self_replace};
73+
pub(crate) use os::{delete_rustup_and_cargo_home, run_update, self_replace};
7474
#[cfg(windows)]
7575
pub use windows::complete_windows_uninstall;
7676

@@ -324,7 +324,7 @@ fn canonical_cargo_home() -> Result<Cow<'static, str>> {
324324
/// Installing is a simple matter of copying the running binary to
325325
/// `CARGO_HOME`/bin, hard-linking the various Rust tools to it,
326326
/// and adding `CARGO_HOME`/bin to PATH.
327-
pub fn install(
327+
pub(crate) fn install(
328328
no_prompt: bool,
329329
verbose: bool,
330330
quiet: bool,
@@ -862,7 +862,7 @@ fn _install_selection<'a>(
862862
})
863863
}
864864

865-
pub fn uninstall(no_prompt: bool) -> Result<utils::ExitCode> {
865+
pub(crate) fn uninstall(no_prompt: bool) -> Result<utils::ExitCode> {
866866
if NEVER_SELF_UPDATE {
867867
err!("self-uninstall is disabled for this build of rustup");
868868
err!("you should probably use your system package manager to uninstall rustup");
@@ -978,7 +978,7 @@ pub fn uninstall(no_prompt: bool) -> Result<utils::ExitCode> {
978978
/// (and on windows this process will not be running to do it),
979979
/// rustup-init is stored in `CARGO_HOME`/bin, and then deleted next
980980
/// time rustup runs.
981-
pub fn update(cfg: &Cfg) -> Result<utils::ExitCode> {
981+
pub(crate) fn update(cfg: &Cfg) -> Result<utils::ExitCode> {
982982
use common::SelfUpdatePermission::*;
983983
let update_permitted = if NEVER_SELF_UPDATE {
984984
HardFail

src/cli/self_update/unix.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::utils::Notification;
1212
// If the user is trying to install with sudo, on some systems this will
1313
// result in writing root-owned files to the user's home directory, because
1414
// sudo is configured not to change $HOME. Don't let that bogosity happen.
15-
pub fn do_anti_sudo_check(no_prompt: bool) -> Result<utils::ExitCode> {
15+
pub(crate) fn do_anti_sudo_check(no_prompt: bool) -> Result<utils::ExitCode> {
1616
pub fn home_mismatch() -> (bool, PathBuf, PathBuf) {
1717
let fallback = || (false, PathBuf::new(), PathBuf::new());
1818
// test runner should set this, nothing else
@@ -126,7 +126,7 @@ pub fn do_remove_from_programs() -> Result<()> {
126126

127127
/// Tell the upgrader to replace the rustup bins, then delete
128128
/// itself.
129-
pub fn run_update(setup_path: &Path) -> Result<utils::ExitCode> {
129+
pub(crate) fn run_update(setup_path: &Path) -> Result<utils::ExitCode> {
130130
let status = Command::new(setup_path)
131131
.arg("--self-replace")
132132
.status()
@@ -142,7 +142,7 @@ pub fn run_update(setup_path: &Path) -> Result<utils::ExitCode> {
142142
/// This function is as the final step of a self-upgrade. It replaces
143143
/// `CARGO_HOME`/bin/rustup with the running exe, and updates the the
144144
/// links to it.
145-
pub fn self_replace() -> Result<utils::ExitCode> {
145+
pub(crate) fn self_replace() -> Result<utils::ExitCode> {
146146
install_bins()?;
147147

148148
Ok(utils::ExitCode(0))

src/command.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use anyhow::{Context, Result};
77
use crate::errors::*;
88
use crate::utils::utils::ExitCode;
99

10-
pub fn run_command_for_dir<S: AsRef<OsStr>>(
10+
pub(crate) fn run_command_for_dir<S: AsRef<OsStr>>(
1111
mut cmd: Command,
1212
arg0: &str,
1313
args: &[S],

src/config.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ pub struct Cfg {
246246
}
247247

248248
impl Cfg {
249-
pub fn from_env(notify_handler: Arc<dyn Fn(Notification<'_>)>) -> Result<Self> {
249+
pub(crate) fn from_env(notify_handler: Arc<dyn Fn(Notification<'_>)>) -> Result<Self> {
250250
// Set up the rustup home directory
251251
let rustup_dir = utils::rustup_home()?;
252252

@@ -359,7 +359,7 @@ impl Cfg {
359359
}
360360

361361
/// construct a download configuration
362-
pub fn download_cfg<'a>(
362+
pub(crate) fn download_cfg<'a>(
363363
&'a self,
364364
notify_handler: &'a dyn Fn(crate::dist::Notification<'_>),
365365
) -> DownloadCfg<'a> {

src/dist/component/package.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl Package for DirectoryPackage {
139139
pub struct TarPackage<'a>(DirectoryPackage, temp::Dir<'a>);
140140

141141
impl<'a> TarPackage<'a> {
142-
pub fn new<R: Read>(
142+
pub(crate) fn new<R: Read>(
143143
stream: R,
144144
temp_cfg: &'a temp::Cfg,
145145
notify_handler: Option<&'a dyn Fn(Notification<'_>)>,
@@ -551,7 +551,7 @@ impl<'a> Package for TarPackage<'a> {
551551
pub struct TarGzPackage<'a>(TarPackage<'a>);
552552

553553
impl<'a> TarGzPackage<'a> {
554-
pub fn new<R: Read>(
554+
pub(crate) fn new<R: Read>(
555555
stream: R,
556556
temp_cfg: &'a temp::Cfg,
557557
notify_handler: Option<&'a dyn Fn(Notification<'_>)>,
@@ -587,7 +587,7 @@ impl<'a> Package for TarGzPackage<'a> {
587587
pub struct TarXzPackage<'a>(TarPackage<'a>);
588588

589589
impl<'a> TarXzPackage<'a> {
590-
pub fn new<R: Read>(
590+
pub(crate) fn new<R: Read>(
591591
stream: R,
592592
temp_cfg: &'a temp::Cfg,
593593
notify_handler: Option<&'a dyn Fn(Notification<'_>)>,
@@ -623,7 +623,7 @@ impl<'a> Package for TarXzPackage<'a> {
623623
pub struct TarZStdPackage<'a>(TarPackage<'a>);
624624

625625
impl<'a> TarZStdPackage<'a> {
626-
pub fn new<R: Read>(
626+
pub(crate) fn new<R: Read>(
627627
stream: R,
628628
temp_cfg: &'a temp::Cfg,
629629
notify_handler: Option<&'a dyn Fn(Notification<'_>)>,

src/dist/component/transaction.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ impl<'a> Transaction<'a> {
168168
pub fn temp(&self) -> &'a temp::Cfg {
169169
self.temp_cfg
170170
}
171-
pub fn notify_handler(&self) -> &'a dyn Fn(Notification<'_>) {
171+
pub(crate) fn notify_handler(&self) -> &'a dyn Fn(Notification<'_>) {
172172
self.notify_handler
173173
}
174174
}

src/dist/manifestation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ impl Manifestation {
379379
}
380380

381381
/// Installation using the legacy v1 manifest format
382-
pub fn update_v1(
382+
pub(crate) fn update_v1(
383383
&self,
384384
new_manifest: &[String],
385385
update_hash: Option<&Path>,

src/dist/notifications.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl<'a> From<temp::Notification<'a>> for Notification<'a> {
5454
}
5555

5656
impl<'a> Notification<'a> {
57-
pub fn level(&self) -> NotificationLevel {
57+
pub(crate) fn level(&self) -> NotificationLevel {
5858
use self::Notification::*;
5959
match self {
6060
Temp(n) => n.level(),

src/dist/temp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub struct File<'a> {
4949
}
5050

5151
impl<'a> Notification<'a> {
52-
pub fn level(&self) -> NotificationLevel {
52+
pub(crate) fn level(&self) -> NotificationLevel {
5353
use self::Notification::*;
5454
match self {
5555
CreatingRoot(_) | CreatingFile(_) | CreatingDirectory(_) => NotificationLevel::Verbose,

src/install.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,11 @@ impl<'a> InstallMethod<'a> {
8686
}
8787
}
8888

89-
pub fn run(self, path: &Path, notify_handler: &dyn Fn(Notification<'_>)) -> Result<bool> {
89+
pub(crate) fn run(
90+
self,
91+
path: &Path,
92+
notify_handler: &dyn Fn(Notification<'_>),
93+
) -> Result<bool> {
9094
if path.exists() {
9195
// Don't uninstall first for Dist method
9296
match self {
@@ -147,6 +151,6 @@ impl<'a> InstallMethod<'a> {
147151
}
148152
}
149153

150-
pub fn uninstall(path: &Path, notify_handler: &dyn Fn(Notification<'_>)) -> Result<()> {
154+
pub(crate) fn uninstall(path: &Path, notify_handler: &dyn Fn(Notification<'_>)) -> Result<()> {
151155
utils::remove_dir("install", path, notify_handler)
152156
}

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub use crate::currentprocess::*;
1313
pub use crate::errors::*;
1414
pub use crate::notifications::*;
1515
pub use crate::toolchain::*;
16-
pub use crate::utils::{notify, toml_utils};
16+
pub(crate) use crate::utils::toml_utils;
1717

1818
#[macro_use]
1919
extern crate rs_tracing;

src/notifications.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl<'a> From<temp::Notification<'a>> for Notification<'a> {
5656
}
5757

5858
impl<'a> Notification<'a> {
59-
pub fn level(&self) -> NotificationLevel {
59+
pub(crate) fn level(&self) -> NotificationLevel {
6060
use self::Notification::*;
6161
match self {
6262
Install(n) => n.level(),

src/settings.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ impl Settings {
108108
}
109109
}
110110

111-
pub fn remove_override(
111+
pub(crate) fn remove_override(
112112
&mut self,
113113
path: &Path,
114114
notify_handler: &dyn Fn(Notification<'_>),
@@ -117,7 +117,7 @@ impl Settings {
117117
self.overrides.remove(&key).is_some()
118118
}
119119

120-
pub fn add_override(
120+
pub(crate) fn add_override(
121121
&mut self,
122122
path: &Path,
123123
toolchain: String,
@@ -128,7 +128,7 @@ impl Settings {
128128
self.overrides.insert(key, toolchain);
129129
}
130130

131-
pub fn dir_override(
131+
pub(crate) fn dir_override(
132132
&self,
133133
dir: &Path,
134134
notify_handler: &dyn Fn(Notification<'_>),

src/utils/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
///! Utility functions for Rustup
2-
pub mod notifications;
2+
pub(crate) mod notifications;
33
pub mod raw;
4-
pub mod toml_utils;
5-
pub mod tty;
6-
pub mod units;
4+
pub(crate) mod toml_utils;
5+
pub(crate) mod tty;
6+
pub(crate) mod units;
77
#[allow(clippy::module_inception)]
88
pub mod utils;
99

10-
pub use crate::utils::notifications::Notification;
11-
pub mod notify;
10+
pub(crate) use crate::utils::notifications::Notification;
11+
pub(crate) mod notify;

src/utils/notifications.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub enum Notification<'a> {
4343
}
4444

4545
impl<'a> Notification<'a> {
46-
pub fn level(&self) -> NotificationLevel {
46+
pub(crate) fn level(&self) -> NotificationLevel {
4747
use self::Notification::*;
4848
match self {
4949
SetDefaultBufferSize(_) => NotificationLevel::Debug,

src/utils/notify.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#[derive(Debug)]
2-
pub enum NotificationLevel {
2+
pub(crate) enum NotificationLevel {
33
Verbose,
44
Info,
55
Warn,

0 commit comments

Comments
 (0)