Skip to content

Commit

Permalink
Upgrade thiserror to 2
Browse files Browse the repository at this point in the history
  • Loading branch information
djc authored and rami3l committed Nov 18, 2024
1 parent 92f84fd commit ac9209d
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 24 deletions.
38 changes: 29 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ platforms = "3.4"
proptest = "1.1.0"
tempfile = "3.8"
termcolor = "1.2"
thiserror = "1.0"
thiserror = "2"
tokio = { version = "1.26.0", default-features = false, features = ["macros", "rt-multi-thread"] }
tokio-retry = { version = "0.3.0" }
tokio-stream = { version = "0.1.14" }
Expand Down
4 changes: 2 additions & 2 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ async fn update(
d.update_extra(&components, &targets, profile, force, allow_downgrade)
.await?
}
Err(RustupError::ToolchainNotInstalled(_)) => {
Err(RustupError::ToolchainNotInstalled { .. }) => {
DistributableToolchain::install(
cfg,
&desc,
Expand Down Expand Up @@ -1341,7 +1341,7 @@ async fn override_add(
let toolchain_name = toolchain.resolve(&cfg.get_default_host_triple()?)?;
match Toolchain::new(cfg, (&toolchain_name).into()) {
Ok(_) => {}
Err(e @ RustupError::ToolchainNotInstalled(_)) => match &toolchain_name {
Err(e @ RustupError::ToolchainNotInstalled { .. }) => match &toolchain_name {
ToolchainName::Custom(_) => Err(e)?,
ToolchainName::Official(desc) => {
let status =
Expand Down
4 changes: 2 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ impl<'a> Cfg<'a> {
// XXX: this awkwardness deals with settings file being locked already
let toolchain_name = toolchain_name.resolve(&default_host_triple)?;
match Toolchain::new(self, (&toolchain_name).into()) {
Err(RustupError::ToolchainNotInstalled(_)) => {
Err(RustupError::ToolchainNotInstalled { .. }) => {
if matches!(toolchain_name, ToolchainName::Custom(_)) {
bail!(
"custom toolchain specified in override file '{}' is not installed",
Expand Down Expand Up @@ -815,7 +815,7 @@ impl<'a> Cfg<'a> {
None => self.get_profile()?,
};
let (status, toolchain) = match DistributableToolchain::new(self, toolchain.clone()) {
Err(RustupError::ToolchainNotInstalled(_)) => {
Err(RustupError::ToolchainNotInstalled { .. }) => {
DistributableToolchain::install(
self,
toolchain,
Expand Down
10 changes: 5 additions & 5 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,19 @@ pub enum RustupError {
#[error("toolchain '{0}' is not installable")]
ToolchainNotInstallable(String),
#[error(
"toolchain '{0}' is not installed{}",
if let ToolchainName::Official(t) = .0 {
"toolchain '{name}' is not installed{}",
if let ToolchainName::Official(t) = name {
format!("\nhelp: run `rustup toolchain install {t}` to install it")
} else {
String::new()
},
)]
ToolchainNotInstalled(ToolchainName),
ToolchainNotInstalled { name: ToolchainName },
#[error("path '{0}' not found")]
PathToolchainNotInstalled(PathBasedToolchainName),
#[error(
"rustup could not choose a version of {0} to run, because one wasn't specified explicitly, and no default is configured.\n{}",
"help: run 'rustup default stable' to download the latest stable release of Rust and set it as your default toolchain."
"rustup could not choose a version of {0} to run, because one wasn't specified explicitly, and no default is configured.\n\
help: run 'rustup default stable' to download the latest stable release of Rust and set it as your default toolchain."
)]
ToolchainNotSelected(String),
#[error("toolchain '{}' does not contain component {}{}{}", .desc, .component, suggest_message(.suggestion), if .component.contains("rust-std") {
Expand Down
10 changes: 5 additions & 5 deletions src/toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ impl<'a> Toolchain<'a> {
) -> anyhow::Result<Toolchain<'a>> {
match Self::new(cfg, name) {
Ok(tc) => Ok(tc),
Err(RustupError::ToolchainNotInstalled(ToolchainName::Official(desc)))
if install_if_missing =>
{
Err(RustupError::ToolchainNotInstalled {
name: ToolchainName::Official(desc),
}) if install_if_missing => {
Ok(
DistributableToolchain::install(cfg, &desc, &[], &[], cfg.get_profile()?, true)
.await?
Expand All @@ -72,7 +72,7 @@ impl<'a> Toolchain<'a> {
reason: &ActiveReason,
) -> anyhow::Result<Self> {
match Self::new(cfg, name.clone()) {
Err(RustupError::ToolchainNotInstalled(_)) => (),
Err(RustupError::ToolchainNotInstalled { .. }) => (),
result => {
return Ok(result?);
}
Expand Down Expand Up @@ -106,7 +106,7 @@ impl<'a> Toolchain<'a> {
let path = cfg.toolchain_path(&name);
if !Toolchain::exists(cfg, &name)? {
return Err(match name {
LocalToolchainName::Named(name) => RustupError::ToolchainNotInstalled(name),
LocalToolchainName::Named(name) => RustupError::ToolchainNotInstalled { name },
LocalToolchainName::Path(name) => RustupError::PathToolchainNotInstalled(name),
});
}
Expand Down

0 comments on commit ac9209d

Please sign in to comment.