diff options
author | Jeff Vander Stoep <jeffv@google.com> | 2023-01-17 22:30:32 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2023-01-17 22:30:32 +0000 |
commit | 326cc2846982db68378188b135a57a1e2e4eb6a0 (patch) | |
tree | 74b35f25c2bf55ab1f00fac536a6a972dbfaead7 | |
parent | fe6dce880f9fece5a99e477c9214a58dd9d96f86 (diff) | |
parent | 7d05dd2f2cfeb736dbdbf659634e56e1b4e5e7e0 (diff) | |
download | anyhow-326cc2846982db68378188b135a57a1e2e4eb6a0.tar.gz |
Upgrade anyhow to 1.0.68 am: 85b5e2f6c5 am: 1cc8d7544c am: 7d05dd2f2c
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/anyhow/+/2391492
Change-Id: Ie1e2789848b1bd24e32408793058dbe5ba370e43
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | .clippy.toml | 2 | ||||
-rw-r--r-- | .github/workflows/ci.yml | 19 | ||||
-rw-r--r-- | Android.bp | 17 | ||||
-rw-r--r-- | Cargo.toml | 18 | ||||
-rw-r--r-- | Cargo.toml.orig | 17 | ||||
-rw-r--r-- | METADATA | 14 | ||||
-rw-r--r-- | README.md | 4 | ||||
-rw-r--r-- | build.rs | 38 | ||||
-rw-r--r-- | cargo2android.json | 6 | ||||
-rw-r--r-- | src/backtrace.rs | 2 | ||||
-rw-r--r-- | src/context.rs | 48 | ||||
-rw-r--r-- | src/ensure.rs | 20 | ||||
-rw-r--r-- | src/error.rs | 40 | ||||
-rw-r--r-- | src/kind.rs | 4 | ||||
-rw-r--r-- | src/lib.rs | 7 | ||||
-rw-r--r-- | src/macros.rs | 32 | ||||
-rw-r--r-- | src/wrapper.rs | 13 | ||||
-rw-r--r-- | tests/test_downcast.rs | 2 | ||||
-rw-r--r-- | tests/test_ensure.rs | 42 | ||||
-rw-r--r-- | tests/test_macros.rs | 1 | ||||
-rw-r--r-- | tests/ui/empty-ensure.stderr | 7 | ||||
-rw-r--r-- | tests/ui/must-use.stderr | 2 | ||||
-rw-r--r-- | tests/ui/no-impl.stderr | 69 | ||||
-rw-r--r-- | tests/ui/temporary-value.stderr | 2 |
25 files changed, 271 insertions, 157 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index c4a86bc..c723f9d 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,6 +1,6 @@ { "git": { - "sha1": "8f950ac0d696644b0ed17d73cb41c1ee30816cf3" + "sha1": "867763b8fce65656a754d8e0d84f0aa1c610613a" }, "path_in_vcs": "" }
\ No newline at end of file diff --git a/.clippy.toml b/.clippy.toml index b32f6d5..78eb145 100644 --- a/.clippy.toml +++ b/.clippy.toml @@ -1 +1 @@ -msrv = "1.34.0" +msrv = "1.38.0" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index db58ee5..02f72f5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,6 +5,9 @@ on: pull_request: schedule: [cron: "40 1 * * *"] +permissions: + contents: read + env: RUSTFLAGS: -Dwarnings @@ -15,7 +18,8 @@ jobs: strategy: fail-fast: false matrix: - rust: [nightly, beta, stable, 1.53.0] + rust: [nightly, beta, stable, 1.56.0] + timeout-minutes: 45 steps: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@master @@ -32,7 +36,8 @@ jobs: strategy: fail-fast: false matrix: - rust: [1.52.0, 1.51.0, 1.50.0, 1.42.0, 1.38.0] + rust: [1.52.0, 1.51.0, 1.50.0, 1.42.0, 1.39.0] + timeout-minutes: 45 steps: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@master @@ -42,11 +47,12 @@ jobs: - run: cargo check - run: cargo check --no-default-features - run: cargo check --features backtrace - if: matrix.rust != '1.38.0' + if: matrix.rust != '1.39.0' && matrix.rust != '1.50.0' windows: name: Windows runs-on: windows-latest + timeout-minutes: 45 steps: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@stable @@ -58,6 +64,7 @@ jobs: name: Clippy runs-on: ubuntu-latest if: github.event_name != 'pull_request' + timeout-minutes: 45 steps: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@nightly @@ -68,11 +75,10 @@ jobs: miri: name: Miri runs-on: ubuntu-latest + timeout-minutes: 45 steps: - uses: actions/checkout@v3 - - uses: dtolnay/rust-toolchain@nightly - with: - components: miri, rust-src + - uses: dtolnay/rust-toolchain@miri - run: cargo miri test env: MIRIFLAGS: -Zmiri-strict-provenance @@ -81,6 +87,7 @@ jobs: name: Outdated runs-on: ubuntu-latest if: github.event_name != 'pull_request' + timeout-minutes: 45 steps: - uses: actions/checkout@v3 - uses: dtolnay/install@cargo-outdated @@ -42,7 +42,7 @@ rust_test { host_supported: true, crate_name: "anyhow", cargo_env_compat: true, - cargo_pkg_version: "1.0.58", + cargo_pkg_version: "1.0.68", srcs: ["src/lib.rs"], test_suites: ["general-tests"], auto_gen_config: true, @@ -64,7 +64,7 @@ rust_defaults { name: "anyhow_test_defaults", crate_name: "anyhow", cargo_env_compat: true, - cargo_pkg_version: "1.0.58", + cargo_pkg_version: "1.0.68", test_suites: ["general-tests"], auto_gen_config: true, edition: "2018", @@ -140,6 +140,16 @@ rust_test { } rust_test { + name: "anyhow_test_tests_test_ffi", + defaults: ["anyhow_test_defaults"], + host_supported: true, + srcs: ["tests/test_ffi.rs"], + test_options: { + unit_test: true, + }, +} + +rust_test { name: "anyhow_test_tests_test_fmt", defaults: ["anyhow_test_defaults"], host_supported: true, @@ -184,7 +194,7 @@ rust_library { host_supported: true, crate_name: "anyhow", cargo_env_compat: true, - cargo_pkg_version: "1.0.58", + cargo_pkg_version: "1.0.68", srcs: ["src/lib.rs"], edition: "2018", features: [ @@ -198,3 +208,4 @@ rust_library { vendor_available: true, min_sdk_version: "29", } + @@ -11,14 +11,21 @@ [package] edition = "2018" -rust-version = "1.38" +rust-version = "1.39" name = "anyhow" -version = "1.0.58" +version = "1.0.68" authors = ["David Tolnay <dtolnay@gmail.com>"] description = "Flexible concrete Error type built on std::error::Error" documentation = "https://docs.rs/anyhow" readme = "README.md" -categories = ["rust-patterns"] +keywords = [ + "error", + "error-handling", +] +categories = [ + "rust-patterns", + "no-std", +] license = "MIT OR Apache-2.0" repository = "https://github.com/dtolnay/anyhow" @@ -29,6 +36,9 @@ rustdoc-args = [ "doc_cfg", ] +[lib] +doc-scrape-examples = false + [dependencies.backtrace] version = "0.3.51" optional = true @@ -48,7 +58,7 @@ features = ["full"] version = "1.0" [dev-dependencies.trybuild] -version = "1.0.49" +version = "1.0.66" features = ["diff"] [features] diff --git a/Cargo.toml.orig b/Cargo.toml.orig index 7232d17..952219e 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,15 +1,15 @@ [package] name = "anyhow" -version = "1.0.58" # remember to update html_root_url +version = "1.0.68" # remember to update html_root_url authors = ["David Tolnay <dtolnay@gmail.com>"] +categories = ["rust-patterns", "no-std"] +description = "Flexible concrete Error type built on std::error::Error" +documentation = "https://docs.rs/anyhow" edition = "2018" -rust-version = "1.38" +keywords = ["error", "error-handling"] license = "MIT OR Apache-2.0" -description = "Flexible concrete Error type built on std::error::Error" repository = "https://github.com/dtolnay/anyhow" -documentation = "https://docs.rs/anyhow" -readme = "README.md" -categories = ["rust-patterns"] +rust-version = "1.39" [features] default = ["std"] @@ -23,7 +23,10 @@ futures = { version = "0.3", default-features = false } rustversion = "1.0.6" syn = { version = "1.0", features = ["full"] } thiserror = "1.0" -trybuild = { version = "1.0.49", features = ["diff"] } +trybuild = { version = "1.0.66", features = ["diff"] } + +[lib] +doc-scrape-examples = false [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] @@ -1,3 +1,7 @@ +# This project was upgraded with external_updater. +# Usage: tools/external_updater/updater.sh update rust/crates/anyhow +# For more info, check https://cs.android.com/android/platform/superproject/+/master:tools/external_updater/README.md + name: "anyhow" description: "Flexible concrete Error type built on std::error::Error" third_party { @@ -7,13 +11,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/anyhow/anyhow-1.0.58.crate" + value: "https://static.crates.io/crates/anyhow/anyhow-1.0.68.crate" } - version: "1.0.58" + version: "1.0.68" license_type: NOTICE last_upgrade_date { - year: 2022 - month: 6 - day: 23 + year: 2023 + month: 1 + day: 17 } } @@ -4,7 +4,7 @@ Anyhow ¯\\\_(°ペ)\_/¯ [<img alt="github" src="https://img.shields.io/badge/github-dtolnay/anyhow-8da0cb?style=for-the-badge&labelColor=555555&logo=github" height="20">](https://github.com/dtolnay/anyhow) [<img alt="crates.io" src="https://img.shields.io/crates/v/anyhow.svg?style=for-the-badge&color=fc8d62&logo=rust" height="20">](https://crates.io/crates/anyhow) [<img alt="docs.rs" src="https://img.shields.io/badge/docs.rs-anyhow-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs" height="20">](https://docs.rs/anyhow) -[<img alt="build status" src="https://img.shields.io/github/workflow/status/dtolnay/anyhow/CI/master?style=for-the-badge" height="20">](https://github.com/dtolnay/anyhow/actions?query=branch%3Amaster) +[<img alt="build status" src="https://img.shields.io/github/actions/workflow/status/dtolnay/anyhow/ci.yml?branch=master&style=for-the-badge" height="20">](https://github.com/dtolnay/anyhow/actions?query=branch%3Amaster) This library provides [`anyhow::Error`][Error], a trait object based error type for easy idiomatic error handling in Rust applications. @@ -16,7 +16,7 @@ for easy idiomatic error handling in Rust applications. anyhow = "1.0" ``` -*Compiler support: requires rustc 1.38+* +*Compiler support: requires rustc 1.39+* <br> @@ -15,15 +15,17 @@ compile_error! { // type. If the current toolchain is able to compile it, we go ahead and use // backtrace in anyhow. const PROBE: &str = r#" - #![feature(backtrace)] - #![allow(dead_code)] + #![feature(error_generic_member_access, provide_any)] + use std::any::{Demand, Provider}; use std::backtrace::{Backtrace, BacktraceStatus}; use std::error::Error; use std::fmt::{self, Display}; #[derive(Debug)] - struct E; + struct E { + backtrace: Backtrace, + } impl Display for E { fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result { @@ -32,14 +34,26 @@ const PROBE: &str = r#" } impl Error for E { - fn backtrace(&self) -> Option<&Backtrace> { - let backtrace = Backtrace::capture(); - match backtrace.status() { - BacktraceStatus::Captured | BacktraceStatus::Disabled | _ => {} - } - unimplemented!() + fn provide<'a>(&'a self, demand: &mut Demand<'a>) { + demand.provide_ref(&self.backtrace); } } + + struct P; + + impl Provider for P { + fn provide<'a>(&'a self, _demand: &mut Demand<'a>) {} + } + + const _: fn() = || { + let backtrace: Backtrace = Backtrace::capture(); + let status: BacktraceStatus = backtrace.status(); + match status { + BacktraceStatus::Captured | BacktraceStatus::Disabled | _ => {} + } + }; + + const _: fn(&dyn Error) -> Option<&Backtrace> = |err| err.request_ref::<Backtrace>(); "#; fn main() { @@ -71,7 +85,7 @@ fn compile_probe() -> Option<ExitStatus> { fs::write(&probefile, PROBE).ok()?; // Make sure to pick up Cargo rustc configuration. - let mut cmd = if let Some(wrapper) = env::var_os("CARGO_RUSTC_WRAPPER") { + let mut cmd = if let Some(wrapper) = env::var_os("RUSTC_WRAPPER") { let mut cmd = Command::new(wrapper); // The wrapper's first argument is supposed to be the path to rustc. cmd.arg(rustc); @@ -89,6 +103,10 @@ fn compile_probe() -> Option<ExitStatus> { .arg(out_dir) .arg(probefile); + if let Some(target) = env::var_os("TARGET") { + cmd.arg("--target").arg(target); + } + // If Cargo wants to set RUSTFLAGS, use that. if let Ok(rustflags) = env::var("CARGO_ENCODED_RUSTFLAGS") { if !rustflags.is_empty() { diff --git a/cargo2android.json b/cargo2android.json index adb0d01..41b0f7c 100644 --- a/cargo2android.json +++ b/cargo2android.json @@ -1,6 +1,7 @@ { "dependencies": true, "dependency-blocklist": [ + "backtrace", "rustversion", "syn", "trybuild" @@ -14,5 +15,8 @@ "tests/test_ensure.rs" ], "tests": true, - "vendor-available": true + "vendor-available": true, + "cfg-blocklist": [ + "backtrace" + ] } diff --git a/src/backtrace.rs b/src/backtrace.rs index e4c9076..23c0c85 100644 --- a/src/backtrace.rs +++ b/src/backtrace.rs @@ -38,7 +38,7 @@ macro_rules! backtrace { #[cfg(backtrace)] macro_rules! backtrace_if_absent { ($err:expr) => { - match $err.backtrace() { + match ($err as &dyn std::error::Error).request_ref::<std::backtrace::Backtrace>() { Some(_) => None, None => backtrace!(), } diff --git a/src/context.rs b/src/context.rs index c228413..9df8693 100644 --- a/src/context.rs +++ b/src/context.rs @@ -4,7 +4,7 @@ use core::convert::Infallible; use core::fmt::{self, Debug, Display, Write}; #[cfg(backtrace)] -use std::backtrace::Backtrace; +use std::any::{Demand, Provider}; mod ext { use super::*; @@ -24,7 +24,7 @@ mod ext { where C: Display + Send + Sync + 'static, { - let backtrace = backtrace_if_absent!(self); + let backtrace = backtrace_if_absent!(&self); Error::from_context(context, self, backtrace) } } @@ -47,7 +47,12 @@ where where C: Display + Send + Sync + 'static, { - self.map_err(|error| error.ext_context(context)) + // Not using map_err to save 2 useless frames off the captured backtrace + // in ext_context. + match self { + Ok(ok) => Ok(ok), + Err(error) => Err(error.ext_context(context)), + } } fn with_context<C, F>(self, context: F) -> Result<T, Error> @@ -55,7 +60,10 @@ where C: Display + Send + Sync + 'static, F: FnOnce() -> C, { - self.map_err(|error| error.ext_context(context())) + match self { + Ok(ok) => Ok(ok), + Err(error) => Err(error.ext_context(context())), + } } } @@ -84,7 +92,12 @@ impl<T> Context<T, Infallible> for Option<T> { where C: Display + Send + Sync + 'static, { - self.ok_or_else(|| Error::from_display(context, backtrace!())) + // Not using ok_or_else to save 2 useless frames off the captured + // backtrace. + match self { + Some(ok) => Ok(ok), + None => Err(Error::from_display(context, backtrace!())), + } } fn with_context<C, F>(self, context: F) -> Result<T, Error> @@ -92,7 +105,10 @@ impl<T> Context<T, Infallible> for Option<T> { C: Display + Send + Sync + 'static, F: FnOnce() -> C, { - self.ok_or_else(|| Error::from_display(context(), backtrace!())) + match self { + Some(ok) => Ok(ok), + None => Err(Error::from_display(context(), backtrace!())), + } } } @@ -123,28 +139,28 @@ where C: Display, E: StdError + 'static, { - #[cfg(backtrace)] - fn backtrace(&self) -> Option<&Backtrace> { - self.error.backtrace() - } - fn source(&self) -> Option<&(dyn StdError + 'static)> { Some(&self.error) } + + #[cfg(backtrace)] + fn provide<'a>(&'a self, demand: &mut Demand<'a>) { + StdError::provide(&self.error, demand); + } } impl<C> StdError for ContextError<C, Error> where C: Display, { - #[cfg(backtrace)] - fn backtrace(&self) -> Option<&Backtrace> { - Some(self.error.backtrace()) - } - fn source(&self) -> Option<&(dyn StdError + 'static)> { Some(unsafe { crate::ErrorImpl::error(self.error.inner.by_ref()) }) } + + #[cfg(backtrace)] + fn provide<'a>(&'a self, demand: &mut Demand<'a>) { + Provider::provide(&self.error, demand); + } } struct Quoted<C>(C); diff --git a/src/ensure.rs b/src/ensure.rs index 80bdab7..0ab4471 100644 --- a/src/ensure.rs +++ b/src/ensure.rs @@ -788,15 +788,15 @@ macro_rules! __fancy_ensure { (lhs, rhs) => { if !(lhs $op rhs) { #[allow(unused_imports)] - use $crate::private::{BothDebug, NotBothDebug}; + use $crate::__private::{BothDebug, NotBothDebug}; return Err((lhs, rhs).__dispatch_ensure( - $crate::private::concat!( + $crate::__private::concat!( "Condition failed: `", - $crate::private::stringify!($lhs), + $crate::__private::stringify!($lhs), " ", - $crate::private::stringify!($op), + $crate::__private::stringify!($op), " ", - $crate::private::stringify!($rhs), + $crate::__private::stringify!($rhs), "`", ), )); @@ -811,24 +811,24 @@ macro_rules! __fancy_ensure { macro_rules! __fallback_ensure { ($cond:expr $(,)?) => { if !$cond { - return $crate::private::Err($crate::Error::msg( - $crate::private::concat!("Condition failed: `", $crate::private::stringify!($cond), "`") + return $crate::__private::Err($crate::Error::msg( + $crate::__private::concat!("Condition failed: `", $crate::__private::stringify!($cond), "`") )); } }; ($cond:expr, $msg:literal $(,)?) => { if !$cond { - return $crate::private::Err($crate::__anyhow!($msg)); + return $crate::__private::Err($crate::__anyhow!($msg)); } }; ($cond:expr, $err:expr $(,)?) => { if !$cond { - return $crate::private::Err($crate::__anyhow!($err)); + return $crate::__private::Err($crate::__anyhow!($err)); } }; ($cond:expr, $fmt:expr, $($arg:tt)*) => { if !$cond { - return $crate::private::Err($crate::__anyhow!($fmt, $($arg)*)); + return $crate::__private::Err($crate::__anyhow!($fmt, $($arg)*)); } }; } diff --git a/src/error.rs b/src/error.rs index 0971146..9f6ce8c 100644 --- a/src/error.rs +++ b/src/error.rs @@ -5,6 +5,8 @@ use crate::ptr::Mut; use crate::ptr::{Own, Ref}; use crate::{Error, StdError}; use alloc::boxed::Box; +#[cfg(backtrace)] +use core::any::Demand; use core::any::TypeId; use core::fmt::{self, Debug, Display}; use core::mem::ManuallyDrop; @@ -31,7 +33,7 @@ impl Error { where E: StdError + Send + Sync + 'static, { - let backtrace = backtrace_if_absent!(error); + let backtrace = backtrace_if_absent!(&error); Error::from_std(error, backtrace) } @@ -522,6 +524,18 @@ impl Error { } } +#[cfg(backtrace)] +impl std::any::Provider for Error { + // Called by thiserror when you have `#[source] anyhow::Error`. This provide + // implementation includes the anyhow::Error's Backtrace if any, unlike + // deref'ing to dyn Error where the provide implementation would include + // only the original error's Backtrace from before it got wrapped into an + // anyhow::Error. + fn provide<'a>(&'a self, demand: &mut Demand<'a>) { + unsafe { ErrorImpl::provide(self.inner.by_ref(), demand) } + } +} + #[cfg(feature = "std")] #[cfg_attr(doc_cfg, doc(cfg(feature = "std")))] impl<E> From<E> for Error @@ -530,7 +544,7 @@ where { #[cold] fn from(error: E) -> Self { - let backtrace = backtrace_if_absent!(error); + let backtrace = backtrace_if_absent!(&error); Error::from_std(error, backtrace) } } @@ -886,13 +900,21 @@ impl ErrorImpl { .as_ref() .or_else(|| { #[cfg(backtrace)] - return Self::error(this).backtrace(); - #[cfg(all(not(backtrace), feature = "backtrace"))] + return Self::error(this).request_ref::<Backtrace>(); + #[cfg(not(backtrace))] return (vtable(this.ptr).object_backtrace)(this); }) .expect("backtrace capture failed") } + #[cfg(backtrace)] + unsafe fn provide<'a>(this: Ref<'a, Self>, demand: &mut Demand<'a>) { + if let Some(backtrace) = &this.deref().backtrace { + demand.provide_ref(backtrace); + } + Self::error(this).provide(demand); + } + #[cold] pub(crate) unsafe fn chain(this: Ref<Self>) -> Chain { Chain::new(Self::error(this)) @@ -903,14 +925,14 @@ impl<E> StdError for ErrorImpl<E> where E: StdError, { - #[cfg(backtrace)] - fn backtrace(&self) -> Option<&Backtrace> { - Some(unsafe { ErrorImpl::backtrace(self.erase()) }) - } - fn source(&self) -> Option<&(dyn StdError + 'static)> { unsafe { ErrorImpl::error(self.erase()).source() } } + + #[cfg(backtrace)] + fn provide<'a>(&'a self, demand: &mut Demand<'a>) { + unsafe { ErrorImpl::provide(self.erase(), demand) } + } } impl<E> Debug for ErrorImpl<E> diff --git a/src/kind.rs b/src/kind.rs index 5985705..f47fe44 100644 --- a/src/kind.rs +++ b/src/kind.rs @@ -40,7 +40,7 @@ // The anyhow! macro will set up the call in this form: // // #[allow(unused_imports)] -// use $crate::private::{AdhocKind, TraitKind}; +// use $crate::__private::{AdhocKind, TraitKind}; // let error = $msg; // (&error).anyhow_kind().new(error) @@ -110,7 +110,7 @@ impl BoxedKind for Box<dyn StdError + Send + Sync> {} impl Boxed { #[cold] pub fn new(self, error: Box<dyn StdError + Send + Sync>) -> Error { - let backtrace = backtrace_if_absent!(error); + let backtrace = backtrace_if_absent!(&*error); Error::from_boxed(error, backtrace) } } @@ -210,14 +210,15 @@ //! will require an explicit `.map_err(Error::msg)` when working with a //! non-Anyhow error type inside a function that returns Anyhow's error type. -#![doc(html_root_url = "https://docs.rs/anyhow/1.0.58")] -#![cfg_attr(backtrace, feature(backtrace))] +#![doc(html_root_url = "https://docs.rs/anyhow/1.0.68")] +#![cfg_attr(backtrace, feature(error_generic_member_access, provide_any))] #![cfg_attr(doc_cfg, feature(doc_cfg))] #![cfg_attr(not(feature = "std"), no_std)] #![deny(dead_code, unused_imports, unused_mut)] #![allow( clippy::doc_markdown, clippy::enum_glob_use, + clippy::explicit_auto_deref, clippy::missing_errors_doc, clippy::missing_panics_doc, clippy::module_name_repetitions, @@ -633,7 +634,7 @@ pub fn Ok<T>(t: T) -> Result<T> { // Not public API. Referenced by macro-generated code. #[doc(hidden)] -pub mod private { +pub mod __private { use crate::Error; use alloc::fmt; use core::fmt::Arguments; diff --git a/src/macros.rs b/src/macros.rs index 5dc1383..6dd2274 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -55,13 +55,13 @@ #[macro_export] macro_rules! bail { ($msg:literal $(,)?) => { - return $crate::private::Err($crate::__anyhow!($msg)) + return $crate::__private::Err($crate::__anyhow!($msg)) }; ($err:expr $(,)?) => { - return $crate::private::Err($crate::__anyhow!($err)) + return $crate::__private::Err($crate::__anyhow!($err)) }; ($fmt:expr, $($arg:tt)*) => { - return $crate::private::Err($crate::__anyhow!($fmt, $($arg)*)) + return $crate::__private::Err($crate::__anyhow!($fmt, $($arg)*)) }; } @@ -120,24 +120,24 @@ macro_rules! bail { macro_rules! ensure { ($cond:expr $(,)?) => { if !$cond { - return $crate::private::Err($crate::Error::msg( - $crate::private::concat!("Condition failed: `", $crate::private::stringify!($cond), "`") + return $crate::__private::Err($crate::Error::msg( + $crate::__private::concat!("Condition failed: `", $crate::__private::stringify!($cond), "`") )); } }; ($cond:expr, $msg:literal $(,)?) => { if !$cond { - return $crate::private::Err($crate::__anyhow!($msg)); + return $crate::__private::Err($crate::__anyhow!($msg)); } }; ($cond:expr, $err:expr $(,)?) => { if !$cond { - return $crate::private::Err($crate::__anyhow!($err)); + return $crate::__private::Err($crate::__anyhow!($err)); } }; ($cond:expr, $fmt:expr, $($arg:tt)*) => { if !$cond { - return $crate::private::Err($crate::__anyhow!($fmt, $($arg)*)); + return $crate::__private::Err($crate::__anyhow!($fmt, $($arg)*)); } }; } @@ -189,14 +189,14 @@ macro_rules! ensure { #[macro_export] macro_rules! anyhow { ($msg:literal $(,)?) => { - $crate::private::must_use({ - let error = $crate::private::format_err($crate::private::format_args!($msg)); + $crate::__private::must_use({ + let error = $crate::__private::format_err($crate::__private::format_args!($msg)); error }) }; ($err:expr $(,)?) => { - $crate::private::must_use({ - use $crate::private::kind::*; + $crate::__private::must_use({ + use $crate::__private::kind::*; let error = match $err { error => (&error).anyhow_kind().new(error), }; @@ -204,7 +204,7 @@ macro_rules! anyhow { }) }; ($fmt:expr, $($arg:tt)*) => { - $crate::Error::msg($crate::private::format!($fmt, $($arg)*)) + $crate::Error::msg($crate::__private::format!($fmt, $($arg)*)) }; } @@ -215,17 +215,17 @@ macro_rules! anyhow { #[macro_export] macro_rules! __anyhow { ($msg:literal $(,)?) => ({ - let error = $crate::private::format_err($crate::private::format_args!($msg)); + let error = $crate::__private::format_err($crate::__private::format_args!($msg)); error }); ($err:expr $(,)?) => ({ - use $crate::private::kind::*; + use $crate::__private::kind::*; let error = match $err { error => (&error).anyhow_kind().new(error), }; error }); ($fmt:expr, $($arg:tt)*) => { - $crate::Error::msg($crate::private::format!($fmt, $($arg)*)) + $crate::Error::msg($crate::__private::format!($fmt, $($arg)*)) }; } diff --git a/src/wrapper.rs b/src/wrapper.rs index 3ebe51a..5f18a50 100644 --- a/src/wrapper.rs +++ b/src/wrapper.rs @@ -1,6 +1,9 @@ use crate::StdError; use core::fmt::{self, Debug, Display}; +#[cfg(backtrace)] +use std::any::Demand; + #[repr(transparent)] pub struct MessageError<M>(pub M); @@ -67,12 +70,12 @@ impl Display for BoxedError { #[cfg(feature = "std")] impl StdError for BoxedError { - #[cfg(backtrace)] - fn backtrace(&self) -> Option<&crate::backtrace::Backtrace> { - self.0.backtrace() - } - fn source(&self) -> Option<&(dyn StdError + 'static)> { self.0.source() } + + #[cfg(backtrace)] + fn provide<'a>(&'a self, demand: &mut Demand<'a>) { + self.0.provide(demand); + } } diff --git a/tests/test_downcast.rs b/tests/test_downcast.rs index 7fb063f..b4470d5 100644 --- a/tests/test_downcast.rs +++ b/tests/test_downcast.rs @@ -1,4 +1,4 @@ -#![allow(clippy::wildcard_imports)] +#![allow(clippy::assertions_on_result_states, clippy::wildcard_imports)] mod common; mod drop; diff --git a/tests/test_ensure.rs b/tests/test_ensure.rs index 4bb12f9..de867f7 100644 --- a/tests/test_ensure.rs +++ b/tests/test_ensure.rs @@ -1,13 +1,13 @@ #![allow( + clippy::bool_to_int_with_if, clippy::diverging_sub_expression, clippy::if_same_then_else, clippy::ifs_same_cond, clippy::items_after_statements, clippy::let_and_return, - clippy::let_underscore_drop, - clippy::logic_bug, clippy::match_bool, clippy::never_loop, + clippy::overly_complex_bool_expr, clippy::redundant_closure_call, clippy::redundant_pattern_matching, clippy::too_many_lines, @@ -17,10 +17,12 @@ irrefutable_let_patterns )] +use self::Enum::Generic; use anyhow::{anyhow, ensure, Chain, Error, Result}; -use std::fmt::Debug; +use std::fmt::{self, Debug}; use std::iter; use std::marker::{PhantomData, PhantomData as P}; +use std::mem; use std::ops::Add; use std::ptr; @@ -43,6 +45,24 @@ trait Trait: Sized { impl<T> Trait for T {} +enum Enum<T: ?Sized> { + #[allow(dead_code)] + Thing(PhantomData<T>), + Generic, +} + +impl<T: ?Sized> PartialEq for Enum<T> { + fn eq(&self, rhs: &Self) -> bool { + mem::discriminant(self) == mem::discriminant(rhs) + } +} + +impl<T: ?Sized> Debug for Enum<T> { + fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + formatter.write_str("Generic") + } +} + #[track_caller] fn assert_err<T: Debug>(result: impl FnOnce() -> Result<T>, expected: &'static str) { let actual = result().unwrap_err().to_string(); @@ -355,27 +375,27 @@ fn test_path() { let test = || Ok(ensure!(E::U::<u8,>>E::U)); assert_err(test, "Condition failed: `E::U::<u8> > E::U` (U vs U)"); - let test = || Ok(ensure!(PhantomData::<dyn Debug + Sync> != PhantomData)); + let test = || Ok(ensure!(Generic::<dyn Debug + Sync> != Generic)); assert_err( test, - "Condition failed: `PhantomData::<dyn Debug + Sync> != PhantomData` (PhantomData vs PhantomData)", + "Condition failed: `Generic::<dyn Debug + Sync> != Generic` (Generic vs Generic)", ); - let test = || Ok(ensure!(PhantomData::<dyn Fn() + Sync> != PhantomData)); + let test = || Ok(ensure!(Generic::<dyn Fn() + Sync> != Generic)); assert_err( test, - "Condition failed: `PhantomData::<dyn Fn() + Sync> != PhantomData` (PhantomData vs PhantomData)", + "Condition failed: `Generic::<dyn Fn() + Sync> != Generic` (Generic vs Generic)", ); #[rustfmt::skip] let test = || { Ok(ensure!( - PhantomData::<dyn Fn::() + ::std::marker::Sync> != PhantomData + Generic::<dyn Fn::() + ::std::marker::Sync> != Generic )) }; assert_err( test, - "Condition failed: `PhantomData::<dyn Fn() + ::std::marker::Sync> != PhantomData` (PhantomData vs PhantomData)", + "Condition failed: `Generic::<dyn Fn() + ::std::marker::Sync> != Generic` (Generic vs Generic)", ); } @@ -408,7 +428,7 @@ fn test_trailer() { let test = || Ok(ensure!(PhantomData::<u8> {} != PhantomData)); assert_err( test, - "Condition failed: `PhantomData::<u8> {} != PhantomData` (PhantomData vs PhantomData)", + "Condition failed: `PhantomData::<u8> {} != PhantomData` (PhantomData<u8> vs PhantomData<u8>)", ); let result = Ok::<_, Error>(1); @@ -596,7 +616,7 @@ fn test_as() { }; assert_err( test, - "Condition failed: `PhantomData as PhantomData<<i32 as ToOwned>::Owned> != PhantomData` (PhantomData vs PhantomData)", + "Condition failed: `PhantomData as PhantomData<<i32 as ToOwned>::Owned> != PhantomData` (PhantomData<i32> vs PhantomData<i32>)", ); macro_rules! int { diff --git a/tests/test_macros.rs b/tests/test_macros.rs index 1ac3970..a3342ab 100644 --- a/tests/test_macros.rs +++ b/tests/test_macros.rs @@ -1,4 +1,5 @@ #![allow( + clippy::assertions_on_result_states, clippy::eq_op, clippy::items_after_statements, clippy::needless_pass_by_value, diff --git a/tests/ui/empty-ensure.stderr b/tests/ui/empty-ensure.stderr index b500de9..bf0229a 100644 --- a/tests/ui/empty-ensure.stderr +++ b/tests/ui/empty-ensure.stderr @@ -4,4 +4,9 @@ error: unexpected end of macro invocation 4 | ensure!(); | ^^^^^^^^^ missing tokens in macro arguments | - = note: this error originates in the macro `$crate::__parse_ensure` (in Nightly builds, run with -Z macro-backtrace for more info) +note: while trying to match meta-variable `$cond:expr` + --> src/ensure.rs + | + | ($cond:expr $(,)?) => { + | ^^^^^^^^^^ + = note: this error originates in the macro `$crate::__parse_ensure` which comes from the expansion of the macro `ensure` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/must-use.stderr b/tests/ui/must-use.stderr index e9ee24b..e10bde4 100644 --- a/tests/ui/must-use.stderr +++ b/tests/ui/must-use.stderr @@ -1,4 +1,4 @@ -error: unused return value of `anyhow::private::must_use` that must be used +error: unused return value of `anyhow::__private::must_use` that must be used --> tests/ui/must-use.rs:8:9 | 8 | anyhow!("it failed"); diff --git a/tests/ui/no-impl.stderr b/tests/ui/no-impl.stderr index 02ab494..1ddf768 100644 --- a/tests/ui/no-impl.stderr +++ b/tests/ui/no-impl.stderr @@ -1,42 +1,31 @@ error[E0599]: the method `anyhow_kind` exists for reference `&Error`, but its trait bounds were not satisfied - --> tests/ui/no-impl.rs:7:13 - | -4 | struct Error; - | ------------- - | | - | doesn't satisfy `Error: Into<anyhow::Error>` - | doesn't satisfy `Error: anyhow::private::kind::TraitKind` - | doesn't satisfy `Error: std::fmt::Display` + --> tests/ui/no-impl.rs:7:13 + | +4 | struct Error; + | ------------ + | | + | doesn't satisfy `Error: Into<anyhow::Error>` + | doesn't satisfy `Error: anyhow::kind::TraitKind` + | doesn't satisfy `Error: std::fmt::Display` ... -7 | let _ = anyhow!(Error); - | ^^^^^^^^^^^^^^ method cannot be called on `&Error` due to unsatisfied trait bounds - | - = note: the following trait bounds were not satisfied: - `Error: Into<anyhow::Error>` - which is required by `Error: anyhow::private::kind::TraitKind` - `Error: std::fmt::Display` - which is required by `&Error: anyhow::private::kind::AdhocKind` - `&Error: Into<anyhow::Error>` - which is required by `&Error: anyhow::private::kind::TraitKind` -note: the following traits must be implemented - --> $RUST/core/src/convert/mod.rs - | - | / pub trait Into<T>: Sized { - | | /// Converts this type into the (usually inferred) input type. - | | #[must_use] - | | #[stable(feature = "rust1", since = "1.0.0")] - | | fn into(self) -> T; - | | } - | |_^ - | - ::: $RUST/core/src/fmt/mod.rs - | - | / pub trait Display { - | | /// Formats the value using the given formatter. - | | /// - | | /// # Examples -... | - | | fn fmt(&self, f: &mut Formatter<'_>) -> Result; - | | } - | |_^ - = note: this error originates in the macro `anyhow` (in Nightly builds, run with -Z macro-backtrace for more info) +7 | let _ = anyhow!(Error); + | ^^^^^^^^^^^^^^ method cannot be called on `&Error` due to unsatisfied trait bounds + | + = note: the following trait bounds were not satisfied: + `Error: Into<anyhow::Error>` + which is required by `Error: anyhow::kind::TraitKind` + `Error: std::fmt::Display` + which is required by `&Error: anyhow::kind::AdhocKind` + `&Error: Into<anyhow::Error>` + which is required by `&Error: anyhow::kind::TraitKind` +note: the traits `Into` and `std::fmt::Display` must be implemented + --> $RUST/core/src/fmt/mod.rs + | + | pub trait Display { + | ^^^^^^^^^^^^^^^^^ + | + ::: $RUST/core/src/convert/mod.rs + | + | pub trait Into<T>: Sized { + | ^^^^^^^^^^^^^^^^^^^^^^^^ + = note: this error originates in the macro `anyhow` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/temporary-value.stderr b/tests/ui/temporary-value.stderr index 4e4115f..dc27c49 100644 --- a/tests/ui/temporary-value.stderr +++ b/tests/ui/temporary-value.stderr @@ -4,6 +4,6 @@ error[E0716]: temporary value dropped while borrowed 4 | let _ = anyhow!(&String::new()); | ---------^^^^^^^^^^^^^- | | | - | | creates a temporary which is freed while still in use + | | creates a temporary value which is freed while still in use | temporary value is freed at the end of this statement | argument requires that borrow lasts for `'static` |