From ac9209da7b1e2664d02cb4cd46f6f55ec110c034 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Mon, 18 Nov 2024 10:40:32 +0100 Subject: [PATCH] Upgrade thiserror to 2 --- Cargo.lock | 38 +++++++++++++++++++++++++++++--------- Cargo.toml | 2 +- src/cli/rustup_mode.rs | 4 ++-- src/config.rs | 4 ++-- src/errors.rs | 10 +++++----- src/toolchain.rs | 10 +++++----- 6 files changed, 44 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1c091a93a2..d5596529f5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -656,7 +656,7 @@ dependencies = [ "rustls", "rustls-platform-verifier", "tempfile", - "thiserror", + "thiserror 2.0.3", "tokio", "tokio-stream", "url", @@ -677,7 +677,7 @@ dependencies = [ "cfg-if 0.1.10", "libc", "sys-info", - "thiserror", + "thiserror 1.0.69", "winapi", ] @@ -1344,7 +1344,7 @@ dependencies = [ "combine", "jni-sys", "log", - "thiserror", + "thiserror 1.0.69", "walkdir", ] @@ -1729,7 +1729,7 @@ dependencies = [ "js-sys", "once_cell", "pin-project-lite", - "thiserror", + "thiserror 1.0.69", ] [[package]] @@ -1745,7 +1745,7 @@ dependencies = [ "opentelemetry-proto", "opentelemetry_sdk", "prost", - "thiserror", + "thiserror 1.0.69", "tokio", "tonic", ] @@ -1778,7 +1778,7 @@ dependencies = [ "percent-encoding", "rand", "serde_json", - "thiserror", + "thiserror 1.0.69", "tokio", "tokio-stream", ] @@ -2316,7 +2316,7 @@ dependencies = [ "tar", "tempfile", "termcolor", - "thiserror", + "thiserror 2.0.3", "threadpool", "tokio", "tokio-retry", @@ -2675,7 +2675,16 @@ version = "1.0.69" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" dependencies = [ - "thiserror-impl", + "thiserror-impl 1.0.69", +] + +[[package]] +name = "thiserror" +version = "2.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c006c85c7651b3cf2ada4584faa36773bd07bac24acfb39f3c431b36d7e667aa" +dependencies = [ + "thiserror-impl 2.0.3", ] [[package]] @@ -2689,6 +2698,17 @@ dependencies = [ "syn", ] +[[package]] +name = "thiserror-impl" +version = "2.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f077553d607adc1caf65430528a576c757a71ed73944b66ebb58ef2bbd243568" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "thread_local" version = "1.1.8" @@ -2816,7 +2836,7 @@ checksum = "0d4770b8024672c1101b3f6733eab95b18007dbe0847a8afe341fcf79e06043f" dependencies = [ "either", "futures-util", - "thiserror", + "thiserror 1.0.69", "tokio", ] diff --git a/Cargo.toml b/Cargo.toml index 2882e3f843..52b786abd2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" } diff --git a/src/cli/rustup_mode.rs b/src/cli/rustup_mode.rs index 547a59dd55..ecf5049bc2 100644 --- a/src/cli/rustup_mode.rs +++ b/src/cli/rustup_mode.rs @@ -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, @@ -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 = diff --git a/src/config.rs b/src/config.rs index f16e375210..009fe136b6 100644 --- a/src/config.rs +++ b/src/config.rs @@ -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", @@ -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, diff --git a/src/errors.rs b/src/errors.rs index d3ef0ca432..c36c75ae4b 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -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") { diff --git a/src/toolchain.rs b/src/toolchain.rs index 7317c0ff8d..8e80838b1a 100644 --- a/src/toolchain.rs +++ b/src/toolchain.rs @@ -50,9 +50,9 @@ impl<'a> Toolchain<'a> { ) -> anyhow::Result> { 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? @@ -72,7 +72,7 @@ impl<'a> Toolchain<'a> { reason: &ActiveReason, ) -> anyhow::Result { match Self::new(cfg, name.clone()) { - Err(RustupError::ToolchainNotInstalled(_)) => (), + Err(RustupError::ToolchainNotInstalled { .. }) => (), result => { return Ok(result?); } @@ -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), }); }