diff options
author | Charisee <chiw@google.com> | 2023-10-13 21:43:39 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2023-10-13 21:43:39 +0000 |
commit | a31b7672c88953e0aae0574f9e2b80840b4b1459 (patch) | |
tree | 9f6ce8c8aadd6c0f53d342b4e30e58a62d7ffe64 | |
parent | 92ad865fc65b9d0e532c91c64e6821e98c872557 (diff) | |
parent | 91e199e0b9ecc10c272914ab0b7c06036cc29646 (diff) | |
download | thiserror-a31b7672c88953e0aae0574f9e2b80840b4b1459.tar.gz |
Update thiserror crate to 1.0.49 am: 91e199e0b9
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/thiserror/+/2786823
Change-Id: I8c10ad7a55b9c7a5190d5c4e8caa4ed20b7d254c
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | Cargo.toml | 15 | ||||
-rw-r--r-- | build.rs | 45 | ||||
-rw-r--r-- | src/aserror.rs | 2 | ||||
-rw-r--r-- | src/display.rs | 36 | ||||
-rw-r--r-- | src/lib.rs | 18 | ||||
-rw-r--r-- | src/provide.rs | 17 | ||||
-rw-r--r-- | tests/test_backtrace.rs | 65 | ||||
-rw-r--r-- | tests/test_display.rs | 2 | ||||
-rw-r--r-- | tests/test_expr.rs | 6 | ||||
-rw-r--r-- | tests/test_generics.rs | 2 | ||||
-rw-r--r-- | tests/test_option.rs | 5 | ||||
-rw-r--r-- | tests/ui/no-display.stderr | 2 |
12 files changed, 123 insertions, 92 deletions
@@ -10,10 +10,10 @@ # See Cargo.toml.orig for the original contents. [package] -edition = "2018" +edition = "2021" rust-version = "1.56" name = "thiserror" -version = "1.0.40" +version = "1.0.49" authors = ["David Tolnay <dtolnay@gmail.com>"] description = "derive(Error)" documentation = "https://docs.rs/thiserror" @@ -28,20 +28,21 @@ license = "MIT OR Apache-2.0" repository = "https://github.com/dtolnay/thiserror" [package.metadata.docs.rs] +rustdoc-args = ["--generate-link-to-definition"] targets = ["x86_64-unknown-linux-gnu"] [dependencies.thiserror-impl] -version = "=1.0.40" +version = "=1.0.49" [dev-dependencies.anyhow] -version = "1.0.65" +version = "1.0.73" [dev-dependencies.ref-cast] -version = "1.0" +version = "1.0.18" [dev-dependencies.rustversion] -version = "1.0" +version = "1.0.13" [dev-dependencies.trybuild] -version = "1.0.66" +version = "1.0.81" features = ["diff"] @@ -4,27 +4,56 @@ use std::path::Path; use std::process::{Command, ExitStatus, Stdio}; use std::str; -// This code exercises the surface area that we expect of the Provider API. If -// the current toolchain is able to compile it, then thiserror is able to use -// providers for backtrace support. +// 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 +// thiserror is able to provide backtrace support. const PROBE: &str = r#" - #![feature(provide_any)] + #![feature(error_generic_member_access)] - use std::any::{Demand, Provider}; + use std::error::{Error, Request}; + use std::fmt::{self, Debug, Display}; - fn _f<'a, P: Provider>(p: &'a P, demand: &mut Demand<'a>) { - p.provide(demand); + struct MyError(Thing); + struct Thing; + + impl Debug for MyError { + fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result { + unimplemented!() + } + } + + impl Display for MyError { + fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result { + unimplemented!() + } + } + + impl Error for MyError { + fn provide<'a>(&'a self, request: &mut Request<'a>) { + request.provide_ref(&self.0); + } } "#; fn main() { match compile_probe() { - Some(status) if status.success() => println!("cargo:rustc-cfg=provide_any"), + Some(status) if status.success() => println!("cargo:rustc-cfg=error_generic_member_access"), _ => {} } } 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/aserror.rs b/src/aserror.rs index 5fea84e..54fc6f1 100644 --- a/src/aserror.rs +++ b/src/aserror.rs @@ -1,6 +1,7 @@ use std::error::Error; use std::panic::UnwindSafe; +#[doc(hidden)] pub trait AsDynError<'a>: Sealed { fn as_dyn_error(&self) -> &(dyn Error + 'a); } @@ -40,6 +41,7 @@ impl<'a> AsDynError<'a> for dyn Error + Send + Sync + UnwindSafe + 'a { } } +#[doc(hidden)] pub trait Sealed {} impl<'a, T: Error + 'a> Sealed for T {} impl<'a> Sealed for dyn Error + 'a {} diff --git a/src/display.rs b/src/display.rs index 0eb0dd9..27098f1 100644 --- a/src/display.rs +++ b/src/display.rs @@ -1,28 +1,40 @@ use std::fmt::Display; use std::path::{self, Path, PathBuf}; -pub trait DisplayAsDisplay { - fn as_display(&self) -> Self; +#[doc(hidden)] +pub trait AsDisplay<'a> { + // TODO: convert to generic associated type. + // https://github.com/dtolnay/thiserror/pull/253 + type Target: Display; + + fn as_display(&'a self) -> Self::Target; } -impl<T: Display> DisplayAsDisplay for &T { - fn as_display(&self) -> Self { - self +impl<'a, T> AsDisplay<'a> for &T +where + T: Display + 'a, +{ + type Target = &'a T; + + fn as_display(&'a self) -> Self::Target { + *self } } -pub trait PathAsDisplay { - fn as_display(&self) -> path::Display<'_>; -} +impl<'a> AsDisplay<'a> for Path { + type Target = path::Display<'a>; -impl PathAsDisplay for Path { - fn as_display(&self) -> path::Display<'_> { + #[inline] + fn as_display(&'a self) -> Self::Target { self.display() } } -impl PathAsDisplay for PathBuf { - fn as_display(&self) -> path::Display<'_> { +impl<'a> AsDisplay<'a> for PathBuf { + type Target = path::Display<'a>; + + #[inline] + fn as_display(&'a self) -> Self::Target { self.display() } } @@ -228,19 +228,18 @@ //! //! [`anyhow`]: https://github.com/dtolnay/anyhow -#![doc(html_root_url = "https://docs.rs/thiserror/1.0.40")] +#![doc(html_root_url = "https://docs.rs/thiserror/1.0.49")] #![allow( - // Clippy bug: https://github.com/rust-lang/rust-clippy/issues/7421 - clippy::doc_markdown, clippy::module_name_repetitions, + clippy::needless_lifetimes, clippy::return_self_not_must_use, - clippy::wildcard_imports, + clippy::wildcard_imports )] -#![cfg_attr(provide_any, feature(provide_any))] +#![cfg_attr(error_generic_member_access, feature(error_generic_member_access))] mod aserror; mod display; -#[cfg(provide_any)] +#[cfg(error_generic_member_access)] mod provide; pub use thiserror_impl::*; @@ -248,8 +247,11 @@ pub use thiserror_impl::*; // Not public API. #[doc(hidden)] pub mod __private { + #[doc(hidden)] pub use crate::aserror::AsDynError; - pub use crate::display::{DisplayAsDisplay, PathAsDisplay}; - #[cfg(provide_any)] + #[doc(hidden)] + pub use crate::display::AsDisplay; + #[cfg(error_generic_member_access)] + #[doc(hidden)] pub use crate::provide::ThiserrorProvide; } diff --git a/src/provide.rs b/src/provide.rs index 524e743..7b4e922 100644 --- a/src/provide.rs +++ b/src/provide.rs @@ -1,15 +1,20 @@ -use std::any::{Demand, Provider}; +use std::error::{Error, Request}; +#[doc(hidden)] pub trait ThiserrorProvide: Sealed { - fn thiserror_provide<'a>(&'a self, demand: &mut Demand<'a>); + fn thiserror_provide<'a>(&'a self, request: &mut Request<'a>); } -impl<T: Provider + ?Sized> ThiserrorProvide for T { +impl<T> ThiserrorProvide for T +where + T: Error + ?Sized, +{ #[inline] - fn thiserror_provide<'a>(&'a self, demand: &mut Demand<'a>) { - self.provide(demand); + fn thiserror_provide<'a>(&'a self, request: &mut Request<'a>) { + self.provide(request); } } +#[doc(hidden)] pub trait Sealed {} -impl<T: Provider + ?Sized> Sealed for T {} +impl<T: Error + ?Sized> Sealed for T {} diff --git a/tests/test_backtrace.rs b/tests/test_backtrace.rs index 43f68b8..4710d45 100644 --- a/tests/test_backtrace.rs +++ b/tests/test_backtrace.rs @@ -1,7 +1,4 @@ -#![cfg_attr( - thiserror_nightly_testing, - feature(error_generic_member_access, provide_any) -)] +#![cfg_attr(thiserror_nightly_testing, feature(error_generic_member_access))] use thiserror::Error; @@ -19,9 +16,8 @@ pub struct InnerBacktrace { #[cfg(thiserror_nightly_testing)] pub mod structs { use super::{Inner, InnerBacktrace}; - use std::any; use std::backtrace::Backtrace; - use std::error::Error; + use std::error::{self, Error}; use std::sync::Arc; use thiserror::Error; @@ -106,75 +102,56 @@ pub mod structs { let error = PlainBacktrace { backtrace: Backtrace::capture(), }; - assert!(any::request_ref::<Backtrace>(&error).is_some()); + assert!(error::request_ref::<Backtrace>(&error).is_some()); let error = ExplicitBacktrace { backtrace: Backtrace::capture(), }; - assert!(any::request_ref::<Backtrace>(&error).is_some()); + assert!(error::request_ref::<Backtrace>(&error).is_some()); let error = OptBacktrace { backtrace: Some(Backtrace::capture()), }; - assert!(any::request_ref::<Backtrace>(&error).is_some()); + assert!(error::request_ref::<Backtrace>(&error).is_some()); let error = ArcBacktrace { backtrace: Arc::new(Backtrace::capture()), }; - assert!(any::request_ref::<Backtrace>(&error).is_some()); + assert!(error::request_ref::<Backtrace>(&error).is_some()); let error = BacktraceFrom::from(Inner); - assert!(any::request_ref::<Backtrace>(&error).is_some()); + assert!(error::request_ref::<Backtrace>(&error).is_some()); let error = CombinedBacktraceFrom::from(InnerBacktrace { backtrace: Backtrace::capture(), }); - assert!(any::request_ref::<Backtrace>(&error).is_some()); + assert!(error::request_ref::<Backtrace>(&error).is_some()); let error = OptBacktraceFrom::from(Inner); - assert!(any::request_ref::<Backtrace>(&error).is_some()); + assert!(error::request_ref::<Backtrace>(&error).is_some()); let error = ArcBacktraceFrom::from(Inner); - assert!(any::request_ref::<Backtrace>(&error).is_some()); + assert!(error::request_ref::<Backtrace>(&error).is_some()); let error = AnyhowBacktrace { source: anyhow::Error::msg("..."), }; - assert!(any::request_ref::<Backtrace>(&error).is_some()); + assert!(error::request_ref::<Backtrace>(&error).is_some()); let error = BoxDynErrorBacktrace { source: Box::new(PlainBacktrace { backtrace: Backtrace::capture(), }), }; - assert!(any::request_ref::<Backtrace>(&error).is_some()); - } - - // https://github.com/dtolnay/thiserror/issues/185 -- std::error::Error and - // std::any::Provide both have a method called 'provide', so directly - // calling it from generated code could be ambiguous. - #[test] - fn test_provide_name_collision() { - use std::any::Provider; - - #[derive(Error, Debug)] - #[error("...")] - struct MyError { - #[source] - #[backtrace] - x: std::io::Error, - } - - let _: dyn Error; - let _: dyn Provider; + assert!(error::request_ref::<Backtrace>(&error).is_some()); } } #[cfg(thiserror_nightly_testing)] pub mod enums { use super::{Inner, InnerBacktrace}; - use std::any; use std::backtrace::Backtrace; + use std::error; use std::sync::Arc; use thiserror::Error; @@ -259,36 +236,36 @@ pub mod enums { let error = PlainBacktrace::Test { backtrace: Backtrace::capture(), }; - assert!(any::request_ref::<Backtrace>(&error).is_some()); + assert!(error::request_ref::<Backtrace>(&error).is_some()); let error = ExplicitBacktrace::Test { backtrace: Backtrace::capture(), }; - assert!(any::request_ref::<Backtrace>(&error).is_some()); + assert!(error::request_ref::<Backtrace>(&error).is_some()); let error = OptBacktrace::Test { backtrace: Some(Backtrace::capture()), }; - assert!(any::request_ref::<Backtrace>(&error).is_some()); + assert!(error::request_ref::<Backtrace>(&error).is_some()); let error = ArcBacktrace::Test { backtrace: Arc::new(Backtrace::capture()), }; - assert!(any::request_ref::<Backtrace>(&error).is_some()); + assert!(error::request_ref::<Backtrace>(&error).is_some()); let error = BacktraceFrom::from(Inner); - assert!(any::request_ref::<Backtrace>(&error).is_some()); + assert!(error::request_ref::<Backtrace>(&error).is_some()); let error = CombinedBacktraceFrom::from(InnerBacktrace { backtrace: Backtrace::capture(), }); - assert!(any::request_ref::<Backtrace>(&error).is_some()); + assert!(error::request_ref::<Backtrace>(&error).is_some()); let error = OptBacktraceFrom::from(Inner); - assert!(any::request_ref::<Backtrace>(&error).is_some()); + assert!(error::request_ref::<Backtrace>(&error).is_some()); let error = ArcBacktraceFrom::from(Inner); - assert!(any::request_ref::<Backtrace>(&error).is_some()); + assert!(error::request_ref::<Backtrace>(&error).is_some()); } } diff --git a/tests/test_display.rs b/tests/test_display.rs index 99ce2fd..6f60388 100644 --- a/tests/test_display.rs +++ b/tests/test_display.rs @@ -1,3 +1,5 @@ +#![allow(clippy::uninlined_format_args)] + use std::fmt::{self, Display}; use thiserror::Error; diff --git a/tests/test_expr.rs b/tests/test_expr.rs index 34de560..8db097b 100644 --- a/tests/test_expr.rs +++ b/tests/test_expr.rs @@ -1,4 +1,8 @@ -#![allow(clippy::iter_cloned_collect, clippy::option_if_let_else)] +#![allow( + clippy::iter_cloned_collect, + clippy::option_if_let_else, + clippy::uninlined_format_args +)] use std::fmt::Display; use thiserror::Error; diff --git a/tests/test_generics.rs b/tests/test_generics.rs index 4ab9f37..c94d95e 100644 --- a/tests/test_generics.rs +++ b/tests/test_generics.rs @@ -1,4 +1,4 @@ -#![allow(clippy::needless_late_init)] +#![allow(clippy::needless_late_init, clippy::uninlined_format_args)] use std::fmt::{self, Debug, Display}; use thiserror::Error; diff --git a/tests/test_option.rs b/tests/test_option.rs index ed5287d..232e5a3 100644 --- a/tests/test_option.rs +++ b/tests/test_option.rs @@ -1,7 +1,4 @@ -#![cfg_attr( - thiserror_nightly_testing, - feature(error_generic_member_access, provide_any) -)] +#![cfg_attr(thiserror_nightly_testing, feature(error_generic_member_access))] #[cfg(thiserror_nightly_testing)] pub mod structs { diff --git a/tests/ui/no-display.stderr b/tests/ui/no-display.stderr index 76818e1..0f47c24 100644 --- a/tests/ui/no-display.stderr +++ b/tests/ui/no-display.stderr @@ -9,7 +9,7 @@ error[E0599]: the method `as_display` exists for reference `&NoDisplay`, but its | = note: the following trait bounds were not satisfied: `NoDisplay: std::fmt::Display` - which is required by `&NoDisplay: DisplayAsDisplay` + which is required by `&NoDisplay: AsDisplay<'_>` note: the trait `std::fmt::Display` must be implemented --> $RUST/core/src/fmt/mod.rs | |