diff --git a/src/cli/self_update.rs b/src/cli/self_update.rs index a8e814d6d1..e42d3fc8b3 100644 --- a/src/cli/self_update.rs +++ b/src/cli/self_update.rs @@ -1106,12 +1106,9 @@ pub(crate) fn update(cfg: &Cfg) -> Result { match prepare_update()? { Some(setup_path) => { - let version = match get_new_rustup_version(&setup_path) { - Some(new_version) => parse_new_rustup_version(new_version), - None => { - err!("failed to get rustup version"); - return Ok(utils::ExitCode(1)); - } + let Some(version) = get_and_parse_new_rustup_version(&setup_path) else { + err!("failed to get rustup version"); + return Ok(utils::ExitCode(1)); }; let _ = common::show_channel_update( @@ -1135,6 +1132,10 @@ pub(crate) fn update(cfg: &Cfg) -> Result { Ok(utils::ExitCode(0)) } +fn get_and_parse_new_rustup_version(path: &Path) -> Option { + get_new_rustup_version(path).map(parse_new_rustup_version) +} + fn get_new_rustup_version(path: &Path) -> Option { match Command::new(path).arg("--version").output() { Err(_) => None,