diff options
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | .clippy.toml | 1 | ||||
-rw-r--r-- | .github/workflows/ci.yml | 17 | ||||
-rw-r--r-- | Android.bp | 24 | ||||
-rw-r--r-- | Cargo.toml | 9 | ||||
-rw-r--r-- | Cargo.toml.orig | 8 | ||||
-rw-r--r-- | METADATA | 21 | ||||
-rw-r--r-- | build.rs | 58 | ||||
-rw-r--r-- | src/backtrace.rs | 2 | ||||
-rw-r--r-- | src/context.rs | 10 | ||||
-rw-r--r-- | src/ensure.rs | 5 | ||||
-rw-r--r-- | src/error.rs | 30 | ||||
-rw-r--r-- | src/kind.rs | 3 | ||||
-rw-r--r-- | src/lib.rs | 13 | ||||
-rw-r--r-- | src/wrapper.rs | 6 | ||||
-rw-r--r-- | tests/test_autotrait.rs | 2 | ||||
-rw-r--r-- | tests/test_backtrace.rs | 2 | ||||
-rw-r--r-- | tests/test_ensure.rs | 4 | ||||
-rw-r--r-- | tests/test_repr.rs | 2 |
19 files changed, 132 insertions, 87 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index 4958ce0..6baca52 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,6 +1,6 @@ { "git": { - "sha1": "58377abfea67601caf6a7051de082484717fe79f" + "sha1": "6485caebde8e5c8bc313cd1a5ff6d70e58670b42" }, "path_in_vcs": "" }
\ No newline at end of file diff --git a/.clippy.toml b/.clippy.toml deleted file mode 100644 index 78eb145..0000000 --- a/.clippy.toml +++ /dev/null @@ -1 +0,0 @@ -msrv = "1.38.0" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 198a836..4ee51c8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,6 +3,7 @@ name: CI on: push: pull_request: + workflow_dispatch: schedule: [cron: "40 1 * * *"] permissions: @@ -31,6 +32,9 @@ jobs: with: toolchain: ${{matrix.rust}} components: rust-src + - name: Enable type layout randomization + run: echo RUSTFLAGS=${RUSTFLAGS}\ -Zrandomize-layout >> $GITHUB_ENV + if: matrix.rust == 'nightly' - run: cargo test - run: cargo check --no-default-features - run: cargo check --features backtrace @@ -54,6 +58,18 @@ jobs: - run: cargo check - run: cargo check --no-default-features + minimal: + name: Minimal versions + needs: pre_ci + if: needs.pre_ci.outputs.continue + runs-on: ubuntu-latest + timeout-minutes: 45 + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@nightly + - run: cargo generate-lockfile -Z minimal-versions + - run: cargo check --locked --features backtrace + windows: name: Windows needs: pre_ci @@ -88,6 +104,7 @@ jobs: steps: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@miri + - run: cargo miri setup - run: cargo miri test env: MIRIFLAGS: -Zmiri-strict-provenance @@ -42,7 +42,7 @@ rust_test { host_supported: true, crate_name: "anyhow", cargo_env_compat: true, - cargo_pkg_version: "1.0.69", + cargo_pkg_version: "1.0.75", srcs: ["src/lib.rs"], test_suites: ["general-tests"], auto_gen_config: true, @@ -65,7 +65,7 @@ rust_test { host_supported: true, crate_name: "test_autotrait", cargo_env_compat: true, - cargo_pkg_version: "1.0.69", + cargo_pkg_version: "1.0.75", srcs: ["tests/test_autotrait.rs"], test_suites: ["general-tests"], auto_gen_config: true, @@ -89,7 +89,7 @@ rust_test { host_supported: true, crate_name: "test_boxed", cargo_env_compat: true, - cargo_pkg_version: "1.0.69", + cargo_pkg_version: "1.0.75", srcs: ["tests/test_boxed.rs"], test_suites: ["general-tests"], auto_gen_config: true, @@ -113,7 +113,7 @@ rust_test { host_supported: true, crate_name: "test_chain", cargo_env_compat: true, - cargo_pkg_version: "1.0.69", + cargo_pkg_version: "1.0.75", srcs: ["tests/test_chain.rs"], test_suites: ["general-tests"], auto_gen_config: true, @@ -137,7 +137,7 @@ rust_test { host_supported: true, crate_name: "test_context", cargo_env_compat: true, - cargo_pkg_version: "1.0.69", + cargo_pkg_version: "1.0.75", srcs: ["tests/test_context.rs"], test_suites: ["general-tests"], auto_gen_config: true, @@ -161,7 +161,7 @@ rust_test { host_supported: true, crate_name: "test_convert", cargo_env_compat: true, - cargo_pkg_version: "1.0.69", + cargo_pkg_version: "1.0.75", srcs: ["tests/test_convert.rs"], test_suites: ["general-tests"], auto_gen_config: true, @@ -185,7 +185,7 @@ rust_test { host_supported: true, crate_name: "test_downcast", cargo_env_compat: true, - cargo_pkg_version: "1.0.69", + cargo_pkg_version: "1.0.75", srcs: ["tests/test_downcast.rs"], test_suites: ["general-tests"], auto_gen_config: true, @@ -209,7 +209,7 @@ rust_test { host_supported: true, crate_name: "test_fmt", cargo_env_compat: true, - cargo_pkg_version: "1.0.69", + cargo_pkg_version: "1.0.75", srcs: ["tests/test_fmt.rs"], test_suites: ["general-tests"], auto_gen_config: true, @@ -233,7 +233,7 @@ rust_test { host_supported: true, crate_name: "test_macros", cargo_env_compat: true, - cargo_pkg_version: "1.0.69", + cargo_pkg_version: "1.0.75", srcs: ["tests/test_macros.rs"], test_suites: ["general-tests"], auto_gen_config: true, @@ -257,7 +257,7 @@ rust_test { host_supported: true, crate_name: "test_repr", cargo_env_compat: true, - cargo_pkg_version: "1.0.69", + cargo_pkg_version: "1.0.75", srcs: ["tests/test_repr.rs"], test_suites: ["general-tests"], auto_gen_config: true, @@ -281,7 +281,7 @@ rust_test { host_supported: true, crate_name: "test_source", cargo_env_compat: true, - cargo_pkg_version: "1.0.69", + cargo_pkg_version: "1.0.75", srcs: ["tests/test_source.rs"], test_suites: ["general-tests"], auto_gen_config: true, @@ -305,7 +305,7 @@ rust_library { host_supported: true, crate_name: "anyhow", cargo_env_compat: true, - cargo_pkg_version: "1.0.69", + cargo_pkg_version: "1.0.75", srcs: ["src/lib.rs"], edition: "2018", features: [ @@ -13,7 +13,7 @@ edition = "2018" rust-version = "1.39" name = "anyhow" -version = "1.0.69" +version = "1.0.75" authors = ["David Tolnay <dtolnay@gmail.com>"] description = "Flexible concrete Error type built on std::error::Error" documentation = "https://docs.rs/anyhow" @@ -30,11 +30,12 @@ license = "MIT OR Apache-2.0" repository = "https://github.com/dtolnay/anyhow" [package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] rustdoc-args = [ "--cfg", "doc_cfg", + "--generate-link-to-definition", ] +targets = ["x86_64-unknown-linux-gnu"] [lib] doc-scrape-examples = false @@ -51,11 +52,11 @@ default-features = false version = "1.0.6" [dev-dependencies.syn] -version = "1.0" +version = "2.0" features = ["full"] [dev-dependencies.thiserror] -version = "1.0" +version = "1.0.45" [dev-dependencies.trybuild] version = "1.0.66" diff --git a/Cargo.toml.orig b/Cargo.toml.orig index b16323b..88be2c2 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,6 +1,6 @@ [package] name = "anyhow" -version = "1.0.69" # remember to update html_root_url +version = "1.0.75" # 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" @@ -21,8 +21,8 @@ backtrace = { version = "0.3.51", optional = true } [dev-dependencies] futures = { version = "0.3", default-features = false } rustversion = "1.0.6" -syn = { version = "1.0", features = ["full"] } -thiserror = "1.0" +syn = { version = "2.0", features = ["full"] } +thiserror = "1.0.45" trybuild = { version = "1.0.66", features = ["diff"] } [lib] @@ -30,4 +30,4 @@ doc-scrape-examples = false [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] -rustdoc-args = ["--cfg", "doc_cfg"] +rustdoc-args = ["--cfg", "doc_cfg", "--generate-link-to-definition"] @@ -1,23 +1,20 @@ # 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 +# For more info, check https://cs.android.com/android/platform/superproject/+/main:tools/external_updater/README.md name: "anyhow" description: "Flexible concrete Error type built on std::error::Error" third_party { - url { - type: HOMEPAGE - value: "https://crates.io/crates/anyhow" - } - url { - type: ARCHIVE - value: "https://static.crates.io/crates/anyhow/anyhow-1.0.69.crate" - } - version: "1.0.69" license_type: NOTICE last_upgrade_date { year: 2023 - month: 2 - day: 15 + month: 12 + day: 4 + } + homepage: "https://crates.io/crates/anyhow" + identifier { + type: "Archive" + value: "https://static.crates.io/crates/anyhow/anyhow-1.0.75.crate" + version: "1.0.75" } } @@ -11,49 +11,38 @@ compile_error! { "`backtrace` feature without `std` feature is not supported" } -// This code exercises the surface area that we expect of the std Backtrace -// type. If the current toolchain is able to compile it, we go ahead and use -// backtrace in anyhow. +// This code exercises the surface area that we expect of the Error generic +// member access API. If the current toolchain is able to compile it, then +// anyhow is able to provide backtrace support. const PROBE: &str = r#" - #![feature(error_generic_member_access, provide_any)] + #![feature(error_generic_member_access)] - use std::any::{Demand, Provider}; - use std::backtrace::{Backtrace, BacktraceStatus}; - use std::error::Error; - use std::fmt::{self, Display}; + use std::backtrace::Backtrace; + use std::error::{self, Error, Request}; + use std::fmt::{self, Debug, Display}; - #[derive(Debug)] - struct E { - backtrace: Backtrace, - } + struct MyError(Thing); + struct Thing; - impl Display for E { + impl Debug for MyError { fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result { unimplemented!() } } - impl Error for E { - fn provide<'a>(&'a self, demand: &mut Demand<'a>) { - demand.provide_ref(&self.backtrace); + impl Display for MyError { + fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result { + unimplemented!() } } - 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 | _ => {} + impl Error for MyError { + fn provide<'a>(&'a self, request: &mut Request<'a>) { + request.provide_ref(&self.0); } - }; + } - const _: fn(&dyn Error) -> Option<&Backtrace> = |err| err.request_ref::<Backtrace>(); + const _: fn(&dyn Error) -> Option<&Backtrace> = |err| error::request_ref::<Backtrace>(err); "#; fn main() { @@ -79,6 +68,17 @@ fn main() { } fn compile_probe() -> Option<ExitStatus> { + if env::var_os("RUSTC_STAGE").is_some() { + // We are running inside rustc bootstrap. This is a highly non-standard + // environment with issues such as: + // + // https://github.com/rust-lang/cargo/issues/11138 + // https://github.com/rust-lang/rust/issues/114839 + // + // Let's just not use nightly features here. + return None; + } + let rustc = env::var_os("RUSTC")?; let out_dir = env::var_os("OUT_DIR")?; let probefile = Path::new(&out_dir).join("probe.rs"); diff --git a/src/backtrace.rs b/src/backtrace.rs index 23c0c85..7c1906b 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 as &dyn std::error::Error).request_ref::<std::backtrace::Backtrace>() { + match std::error::request_ref::<std::backtrace::Backtrace>($err as &dyn std::error::Error) { Some(_) => None, None => backtrace!(), } diff --git a/src/context.rs b/src/context.rs index 9df8693..d81b9a7 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::any::{Demand, Provider}; +use std::error::Request; mod ext { use super::*; @@ -144,8 +144,8 @@ where } #[cfg(backtrace)] - fn provide<'a>(&'a self, demand: &mut Demand<'a>) { - StdError::provide(&self.error, demand); + fn provide<'a>(&'a self, request: &mut Request<'a>) { + StdError::provide(&self.error, request); } } @@ -158,8 +158,8 @@ where } #[cfg(backtrace)] - fn provide<'a>(&'a self, demand: &mut Demand<'a>) { - Provider::provide(&self.error, demand); + fn provide<'a>(&'a self, request: &mut Request<'a>) { + Error::provide(&self.error, request); } } diff --git a/src/ensure.rs b/src/ensure.rs index 0ab4471..c40cb92 100644 --- a/src/ensure.rs +++ b/src/ensure.rs @@ -231,6 +231,11 @@ macro_rules! __parse_ensure { $crate::__parse_ensure!(atom $stack $bail ($($fuel)*) {($($buf)* $unsafe $block) $($parse)*} ($($rest)*) $($rest)*) }; + (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} ($const:tt $block:tt $($dup:tt)*) const {$($body:tt)*} $($rest:tt)*) => { + // TODO: this is mostly useless due to https://github.com/rust-lang/rust/issues/86730 + $crate::__parse_ensure!(atom $stack $bail ($($fuel)*) {($($buf)* $const $block) $($parse)*} ($($rest)*) $($rest)*) + }; + (0 $stack:tt $bail:tt (~$($fuel:tt)*) {($($buf:tt)*) $($parse:tt)*} $dup:tt $lit:literal $($rest:tt)*) => { $crate::__parse_ensure!(atom $stack $bail ($($fuel)*) {($($buf)* $lit) $($parse)*} ($($rest)*) $($rest)*) }; diff --git a/src/error.rs b/src/error.rs index 9f6ce8c..01402d4 100644 --- a/src/error.rs +++ b/src/error.rs @@ -5,14 +5,14 @@ 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; #[cfg(not(anyhow_no_ptr_addr_of))] use core::ptr; use core::ptr::NonNull; +#[cfg(backtrace)] +use std::error::{self, Request}; #[cfg(feature = "std")] use core::ops::{Deref, DerefMut}; @@ -522,17 +522,21 @@ impl Error { Some(addr.cast::<E>().deref_mut()) } } -} -#[cfg(backtrace)] -impl std::any::Provider for Error { + #[cfg(backtrace)] + pub(crate) fn provide<'a>(&'a self, request: &mut Request<'a>) { + unsafe { ErrorImpl::provide(self.inner.by_ref(), request) } + } + // 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(backtrace)] + #[doc(hidden)] + pub fn thiserror_provide<'a>(&'a self, request: &mut Request<'a>) { + Self::provide(self, request); } } @@ -900,7 +904,7 @@ impl ErrorImpl { .as_ref() .or_else(|| { #[cfg(backtrace)] - return Self::error(this).request_ref::<Backtrace>(); + return error::request_ref::<Backtrace>(Self::error(this)); #[cfg(not(backtrace))] return (vtable(this.ptr).object_backtrace)(this); }) @@ -908,11 +912,11 @@ impl ErrorImpl { } #[cfg(backtrace)] - unsafe fn provide<'a>(this: Ref<'a, Self>, demand: &mut Demand<'a>) { + unsafe fn provide<'a>(this: Ref<'a, Self>, request: &mut Request<'a>) { if let Some(backtrace) = &this.deref().backtrace { - demand.provide_ref(backtrace); + request.provide_ref(backtrace); } - Self::error(this).provide(demand); + Self::error(this).provide(request); } #[cold] @@ -930,8 +934,8 @@ where } #[cfg(backtrace)] - fn provide<'a>(&'a self, demand: &mut Demand<'a>) { - unsafe { ErrorImpl::provide(self.erase(), demand) } + fn provide<'a>(&'a self, request: &mut Request<'a>) { + unsafe { ErrorImpl::provide(self.erase(), request) } } } diff --git a/src/kind.rs b/src/kind.rs index f47fe44..21d76aa 100644 --- a/src/kind.rs +++ b/src/kind.rs @@ -52,6 +52,7 @@ use crate::StdError; pub struct Adhoc; +#[doc(hidden)] pub trait AdhocKind: Sized { #[inline] fn anyhow_kind(&self) -> Adhoc { @@ -73,6 +74,7 @@ impl Adhoc { pub struct Trait; +#[doc(hidden)] pub trait TraitKind: Sized { #[inline] fn anyhow_kind(&self) -> Trait { @@ -96,6 +98,7 @@ impl Trait { pub struct Boxed; #[cfg(feature = "std")] +#[doc(hidden)] pub trait BoxedKind: Sized { #[inline] fn anyhow_kind(&self) -> Boxed { @@ -210,8 +210,8 @@ //! 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.69")] -#![cfg_attr(backtrace, feature(error_generic_member_access, provide_any))] +#![doc(html_root_url = "https://docs.rs/anyhow/1.0.75")] +#![cfg_attr(backtrace, feature(error_generic_member_access))] #![cfg_attr(doc_cfg, feature(doc_cfg))] #![cfg_attr(not(feature = "std"), no_std)] #![deny(dead_code, unused_imports, unused_mut)] @@ -219,6 +219,8 @@ clippy::doc_markdown, clippy::enum_glob_use, clippy::explicit_auto_deref, + clippy::extra_unused_type_parameters, + clippy::let_underscore_untyped, clippy::missing_errors_doc, clippy::missing_panics_doc, clippy::module_name_repetitions, @@ -264,6 +266,7 @@ trait StdError: Debug + Display { } } +#[doc(no_inline)] pub use anyhow as format_err; /// The `Error` type, a wrapper around a dynamic error type. @@ -639,16 +642,22 @@ pub mod __private { use alloc::fmt; use core::fmt::Arguments; + #[doc(hidden)] pub use crate::ensure::{BothDebug, NotBothDebug}; + #[doc(hidden)] pub use alloc::format; + #[doc(hidden)] pub use core::result::Result::Err; + #[doc(hidden)] pub use core::{concat, format_args, stringify}; #[doc(hidden)] pub mod kind { + #[doc(hidden)] pub use crate::kind::{AdhocKind, TraitKind}; #[cfg(feature = "std")] + #[doc(hidden)] pub use crate::kind::BoxedKind; } diff --git a/src/wrapper.rs b/src/wrapper.rs index 5f18a50..8a6d686 100644 --- a/src/wrapper.rs +++ b/src/wrapper.rs @@ -2,7 +2,7 @@ use crate::StdError; use core::fmt::{self, Debug, Display}; #[cfg(backtrace)] -use std::any::Demand; +use std::error::Request; #[repr(transparent)] pub struct MessageError<M>(pub M); @@ -75,7 +75,7 @@ impl StdError for BoxedError { } #[cfg(backtrace)] - fn provide<'a>(&'a self, demand: &mut Demand<'a>) { - self.0.provide(demand); + fn provide<'a>(&'a self, request: &mut Request<'a>) { + self.0.provide(request); } } diff --git a/tests/test_autotrait.rs b/tests/test_autotrait.rs index 0c9326d..94d7a59 100644 --- a/tests/test_autotrait.rs +++ b/tests/test_autotrait.rs @@ -1,3 +1,5 @@ +#![allow(clippy::extra_unused_type_parameters)] + use anyhow::Error; #[test] diff --git a/tests/test_backtrace.rs b/tests/test_backtrace.rs index ce385f5..c89559e 100644 --- a/tests/test_backtrace.rs +++ b/tests/test_backtrace.rs @@ -1,3 +1,5 @@ +#![allow(clippy::let_underscore_untyped)] + #[rustversion::not(nightly)] #[ignore] #[test] diff --git a/tests/test_ensure.rs b/tests/test_ensure.rs index de867f7..aeff3ac 100644 --- a/tests/test_ensure.rs +++ b/tests/test_ensure.rs @@ -1,11 +1,15 @@ #![allow( clippy::bool_to_int_with_if, clippy::diverging_sub_expression, + clippy::extra_unused_type_parameters, clippy::if_same_then_else, clippy::ifs_same_cond, + clippy::ignored_unit_patterns, clippy::items_after_statements, clippy::let_and_return, + clippy::let_underscore_untyped, clippy::match_bool, + clippy::needless_else, clippy::never_loop, clippy::overly_complex_bool_expr, clippy::redundant_closure_call, diff --git a/tests/test_repr.rs b/tests/test_repr.rs index 72f5002..065041c 100644 --- a/tests/test_repr.rs +++ b/tests/test_repr.rs @@ -1,3 +1,5 @@ +#![allow(clippy::extra_unused_type_parameters)] + mod drop; use self::drop::{DetectDrop, Flag}; |