Skip to content

Commit

Permalink
fix(utils): make ExitCode #[must_use]
Browse files Browse the repository at this point in the history
  • Loading branch information
rami3l committed Jul 17, 2024
1 parent 3fa1790 commit e835ca4
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
5 changes: 2 additions & 3 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ async fn update(cfg: &mut Cfg<'_>, opts: UpdateOpts) -> Result<utils::ExitCode>
}
}
if self_update {
common::self_update(|| Ok(()), cfg.process).await?;
exit_code &= common::self_update(|| Ok(()), cfg.process).await?;
}
} else {
exit_code &= common::update_all_channels(cfg, self_update, opts.force).await?;
Expand Down Expand Up @@ -1205,8 +1205,7 @@ async fn component_list(
installed_only,
quiet,
cfg.process,
)?;
Ok(utils::ExitCode(0))
)
}

async fn component_add(
Expand Down
9 changes: 7 additions & 2 deletions src/cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,9 @@ pub(crate) async fn install(
mut opts: InstallOpts<'_>,
process: &Process,
) -> Result<utils::ExitCode> {
#[cfg_attr(not(unix), allow(unused_mut))]
let mut exit_code = utils::ExitCode(0);

opts.validate(process).map_err(|e| {
anyhow!(
"Pre-checks for host and toolchain failed: {e}\n\
Expand All @@ -513,7 +516,9 @@ pub(crate) async fn install(
}

#[cfg(unix)]
unix::do_anti_sudo_check(no_prompt, process)?;
{
exit_code &= unix::do_anti_sudo_check(no_prompt, process)?;
}

let mut term = process.stdout().terminal(process);

Expand Down Expand Up @@ -590,7 +595,7 @@ pub(crate) async fn install(
windows::ensure_prompt(process)?;
}

Ok(utils::ExitCode(0))
Ok(exit_code)
}

fn rustc_or_cargo_exists_in_path(process: &Process) -> Result<()> {
Expand Down
3 changes: 1 addition & 2 deletions src/cli/setup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ pub async fn main(
}

if dump_testament {
common::dump_testament(process)?;
return Ok(utils::ExitCode(0));
return common::dump_testament(process);
}

if profile == Profile::Complete {
Expand Down
1 change: 1 addition & 0 deletions src/utils/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub(crate) use crate::utils::utils::raw::is_directory;

pub use crate::utils::utils::raw::{is_file, path_exists};

#[must_use]
#[derive(Debug, PartialEq, Eq)]
pub struct ExitCode(pub i32);

Expand Down

0 comments on commit e835ca4

Please sign in to comment.