Skip to content

Commit 60b9351

Browse files
committed
Unwrap Option<Path> early
1 parent 3008ac7 commit 60b9351

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

src/cli/self_update.rs

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -399,11 +399,11 @@ fn check_existence_of_rustc_or_cargo_in_path(no_prompt: bool) -> Result<()> {
399399
fn do_pre_install_sanity_checks() -> Result<()> {
400400
let rustc_manifest_path = PathBuf::from("/usr/local/lib/rustlib/manifest-rustc");
401401
let uninstaller_path = PathBuf::from("/usr/local/lib/rustlib/uninstall.sh");
402-
let rustup_sh_path = utils::home_dir().map(|d| d.join(".rustup"));
403-
let rustup_sh_version_path = rustup_sh_path.as_ref().map(|p| p.join("rustup-version"));
402+
let rustup_sh_path = utils::home_dir().unwrap().join(".rustup");
403+
let rustup_sh_version_path = rustup_sh_path.join("rustup-version");
404404

405405
let rustc_exists = rustc_manifest_path.exists() && uninstaller_path.exists();
406-
let rustup_sh_exists = rustup_sh_version_path.map(|p| p.exists()) == Some(true);
406+
let rustup_sh_exists = rustup_sh_version_path.exists();
407407

408408
if rustc_exists {
409409
warn!("it looks like you have an existing installation of Rust");
@@ -418,10 +418,7 @@ fn do_pre_install_sanity_checks() -> Result<()> {
418418
if rustup_sh_exists {
419419
warn!("it looks like you have existing rustup.sh metadata");
420420
warn!("rustup cannot be installed while rustup.sh metadata exists");
421-
warn!(
422-
"delete `{}` to remove rustup.sh",
423-
rustup_sh_path.unwrap().display()
424-
);
421+
warn!("delete `{}` to remove rustup.sh", rustup_sh_path.display());
425422
warn!("or, if you already have rustup installed, you can run");
426423
warn!("`rustup self update` and `rustup toolchain list` to upgrade");
427424
warn!("your directory structure");
@@ -711,7 +708,7 @@ pub fn install_proxies() -> Result<()> {
711708
if tool_handles.iter().all(|h| *h != handle) {
712709
warn!("tool `{}` is already installed, remove it from `{}`, then run `rustup update` \
713710
to have rustup manage this tool.",
714-
tool, bin_path.to_string_lossy());
711+
tool, bin_path.display());
715712
continue;
716713
}
717714
}
@@ -1094,30 +1091,27 @@ fn get_add_path_methods() -> Vec<PathUpdateMethod> {
10941091
return vec![PathUpdateMethod::Windows];
10951092
}
10961093

1097-
let profile = utils::home_dir().map(|p| p.join(".profile"));
1094+
let home_dir = utils::home_dir().unwrap();
1095+
let profile = home_dir.join(".profile");
10981096
let mut profiles = vec![profile];
10991097

11001098
if let Ok(shell) = env::var("SHELL") {
11011099
if shell.contains("zsh") {
1102-
let zdotdir = env::var("ZDOTDIR")
1103-
.ok()
1104-
.map(PathBuf::from)
1105-
.or_else(utils::home_dir);
1106-
let zprofile = zdotdir.map(|p| p.join(".zprofile"));
1100+
let var = env::var_os("ZDOTDIR");
1101+
let zdotdir = var.as_deref().map_or_else(|| home_dir.as_path(), Path::new);
1102+
let zprofile = zdotdir.join(".zprofile");
11071103
profiles.push(zprofile);
11081104
}
11091105
}
11101106

1111-
if let Some(bash_profile) = utils::home_dir().map(|p| p.join(".bash_profile")) {
1112-
// Only update .bash_profile if it exists because creating .bash_profile
1113-
// will cause .profile to not be read
1114-
if bash_profile.exists() {
1115-
profiles.push(Some(bash_profile));
1116-
}
1107+
let bash_profile = home_dir.join(".bash_profile");
1108+
// Only update .bash_profile if it exists because creating .bash_profile
1109+
// will cause .profile to not be read
1110+
if bash_profile.exists() {
1111+
profiles.push(bash_profile);
11171112
}
11181113

1119-
let rcfiles = profiles.into_iter().filter_map(|f| f);
1120-
rcfiles.map(PathUpdateMethod::RcFile).collect()
1114+
profiles.into_iter().map(PathUpdateMethod::RcFile).collect()
11211115
}
11221116

11231117
fn shell_export_string() -> Result<String> {

0 commit comments

Comments
 (0)