diff --git a/src/cli/common.rs b/src/cli/common.rs index 8fc03b632f1..ea5e38b7e8a 100644 --- a/src/cli/common.rs +++ b/src/cli/common.rs @@ -314,10 +314,7 @@ pub(crate) async fn update_all_channels( }; if do_self_update { - let self_update_exit_code = self_update(show_channel_updates, cfg.process).await?; - if self_update_exit_code != utils::ExitCode(0) { - exit_code = self_update_exit_code; - } + exit_code &= self_update(show_channel_updates, cfg.process).await?; } else { show_channel_updates()?; } diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index 60db37fe749..a82176fb238 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -867,7 +867,7 @@ async fn update(cfg: &mut Cfg<'_>, opts: UpdateOpts) -> Result common::self_update(|| Ok(()), cfg.process).await?; } } else { - exit_code = common::update_all_channels(cfg, self_update, opts.force).await?; + exit_code &= common::update_all_channels(cfg, self_update, opts.force).await?; info!("cleaning up downloads & tmp directories"); utils::delete_dir_contents_following_links(&cfg.download_dir); cfg.tmp_cx.clean(); diff --git a/src/utils/utils.rs b/src/utils/utils.rs index 64619f4c915..826838842c4 100644 --- a/src/utils/utils.rs +++ b/src/utils/utils.rs @@ -1,6 +1,7 @@ use std::env; use std::fs::{self, File}; use std::io::{self, BufReader, Write}; +use std::ops::{BitAnd, BitAndAssign}; use std::path::{Path, PathBuf}; use std::process::ExitStatus; @@ -24,6 +25,25 @@ pub use crate::utils::utils::raw::{is_file, path_exists}; #[derive(Debug, PartialEq, Eq)] pub struct ExitCode(pub i32); +impl BitAnd for ExitCode { + type Output = Self; + + fn bitand(self, rhs: Self) -> Self::Output { + match self.0 { + 0 => rhs, + _ => self, + } + } +} + +impl BitAndAssign for ExitCode { + fn bitand_assign(&mut self, rhs: Self) { + if self.0 == 0 { + *self = rhs + } + } +} + impl From for ExitCode { fn from(status: ExitStatus) -> Self { Self(match status.success() {