Skip to content

Commit dfc9205

Browse files
committed
Store process name in error variant directly
1 parent c616683 commit dfc9205

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

src/config.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,7 @@ impl OverrideCfg {
165165
path.display()
166166
)
167167
}
168-
(None, None) => cfg
169-
.get_default()?
170-
.ok_or(RustupError::ToolchainNotSelected)?,
168+
(None, None) => cfg.get_default()?.ok_or_else(no_toolchain_error)?,
171169
};
172170
Ok(match toolchain_name {
173171
ToolchainName::Official(desc) => {
@@ -692,7 +690,7 @@ impl Cfg {
692690
) -> Result<(Toolchain<'_>, ActiveReason)> {
693691
self.maybe_find_or_install_active_toolchain(&self.current_dir)
694692
.await?
695-
.ok_or(RustupError::ToolchainNotSelected.into())
693+
.ok_or_else(no_toolchain_error)
696694
}
697695

698696
#[cfg_attr(feature = "otel", tracing::instrument(skip_all))]
@@ -957,6 +955,10 @@ fn get_default_host_triple(s: &Settings) -> dist::TargetTriple {
957955
.unwrap_or_else(dist::TargetTriple::from_host_or_build)
958956
}
959957

958+
fn no_toolchain_error() -> anyhow::Error {
959+
RustupError::ToolchainNotSelected(process().name().unwrap_or_else(|| "Rust".into())).into()
960+
}
961+
960962
/// Specifies how a `rust-toolchain`/`rust-toolchain.toml` configuration file should be parsed.
961963
enum ParseMode {
962964
/// Only permit TOML format in a configuration file.

src/errors.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ use std::path::PathBuf;
1010
use thiserror::Error as ThisError;
1111
use url::Url;
1212

13-
use crate::{
14-
currentprocess::process,
15-
dist::dist::{TargetTriple, ToolchainDesc},
16-
};
13+
use crate::dist::dist::{TargetTriple, ToolchainDesc};
1714
use crate::{
1815
dist::manifest::{Component, Manifest},
1916
toolchain::names::{PathBasedToolchainName, ToolchainName},
@@ -92,11 +89,10 @@ pub enum RustupError {
9289
#[error("path '{0}' not found")]
9390
PathToolchainNotInstalled(PathBasedToolchainName),
9491
#[error(
95-
"rustup could not choose a version of {} to run, because one wasn't specified explicitly, and no default is configured.\n{}",
96-
process().name().unwrap_or_else(|| "Rust".into()),
92+
"rustup could not choose a version of {0} to run, because one wasn't specified explicitly, and no default is configured.\n{}",
9793
"help: run 'rustup default stable' to download the latest stable release of Rust and set it as your default toolchain."
9894
)]
99-
ToolchainNotSelected,
95+
ToolchainNotSelected(String),
10096
#[error("toolchain '{}' does not contain component {}{}{}", .desc, .component, suggest_message(.suggestion), if .component.contains("rust-std") {
10197
format!("\nnote: not all platforms have the standard library pre-compiled: https://doc.rust-lang.org/nightly/rustc/platform-support.html{}",
10298
if desc.channel == "nightly" { "\nhelp: consider using `cargo build -Z build-std` instead" } else { "" }

0 commit comments

Comments
 (0)