diff options
author | Joel Galenson <jgalenson@google.com> | 2021-10-12 16:12:24 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-10-12 16:12:24 +0000 |
commit | 034c4b993ecadbdfd105931d6e31c1d800bd4c06 (patch) | |
tree | f25b373e9bbc8db561e78b852158174cab38b01d | |
parent | 2c59809926dd69b6699a0d8f0e762d51f5ffed17 (diff) | |
parent | cbfa3acfa19c420d67fbff9bbdb5c69ee4ec347e (diff) | |
download | thiserror-034c4b993ecadbdfd105931d6e31c1d800bd4c06.tar.gz |
Merge "Upgrade rust/crates/thiserror to 1.0.29" am: d1617d538f am: b48cebb01a am: e080fb9834 am: a05a0ea13a am: cbfa3acfa1
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/thiserror/+/1833621
Change-Id: I98492ea8bec946fec4fab180ffed7326a8ec949f
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | Android.bp | 9 | ||||
-rw-r--r-- | Cargo.toml | 13 | ||||
-rw-r--r-- | Cargo.toml.orig | 4 | ||||
-rw-r--r-- | METADATA | 8 | ||||
-rw-r--r-- | README.md | 14 | ||||
-rw-r--r-- | src/lib.rs | 16 | ||||
-rw-r--r-- | tests/test_backtrace.rs | 43 | ||||
-rw-r--r-- | tests/test_display.rs | 4 | ||||
-rw-r--r-- | tests/test_expr.rs | 6 | ||||
-rw-r--r-- | tests/test_from.rs | 27 | ||||
-rw-r--r-- | tests/test_generics.rs | 161 | ||||
-rw-r--r-- | tests/test_lints.rs | 5 | ||||
-rw-r--r-- | tests/test_path.rs | 4 | ||||
-rw-r--r-- | tests/test_source.rs | 4 | ||||
-rw-r--r-- | tests/test_transparent.rs | 4 |
16 files changed, 267 insertions, 57 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index 16f81ed..d146052 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,5 +1,5 @@ { "git": { - "sha1": "031fea6f3b82c72be11477e7550c6ae3579e6139" + "sha1": "c7dd271dcd92af17168746a809503ee392d6f6ad" } } @@ -41,6 +41,8 @@ rust_library { name: "libthiserror", host_supported: true, crate_name: "thiserror", + cargo_env_compat: true, + cargo_pkg_version: "1.0.29", srcs: ["src/lib.rs"], edition: "2018", proc_macros: ["libthiserror_impl"], @@ -50,10 +52,3 @@ rust_library { "com.android.virt", ], } - -// dependent_library ["feature_list"] -// proc-macro2-1.0.28 "default,proc-macro" -// quote-1.0.9 "default,proc-macro" -// syn-1.0.74 "clone-impls,default,derive,parsing,printing,proc-macro,quote" -// thiserror-impl-1.0.26 -// unicode-xid-0.2.2 "default" @@ -3,17 +3,16 @@ # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies -# to registry (e.g., crates.io) dependencies +# to registry (e.g., crates.io) dependencies. # -# If you believe there's an error in this file please file an -# issue against the rust-lang/cargo repository. If you're -# editing this file be aware that the upstream Cargo.toml -# will likely look very different (and much more reasonable) +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. [package] edition = "2018" name = "thiserror" -version = "1.0.26" +version = "1.0.29" authors = ["David Tolnay <dtolnay@gmail.com>"] description = "derive(Error)" documentation = "https://docs.rs/thiserror" @@ -24,7 +23,7 @@ repository = "https://github.com/dtolnay/thiserror" [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] [dependencies.thiserror-impl] -version = "=1.0.26" +version = "=1.0.29" [dev-dependencies.anyhow] version = "1.0" diff --git a/Cargo.toml.orig b/Cargo.toml.orig index dd0b38e..f619245 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,6 +1,6 @@ [package] name = "thiserror" -version = "1.0.26" +version = "1.0.29" authors = ["David Tolnay <dtolnay@gmail.com>"] edition = "2018" license = "MIT OR Apache-2.0" @@ -11,7 +11,7 @@ categories = ["rust-patterns"] readme = "README.md" [dependencies] -thiserror-impl = { version = "=1.0.26", path = "impl" } +thiserror-impl = { version = "=1.0.29", path = "impl" } [dev-dependencies] anyhow = "1.0" @@ -7,13 +7,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/thiserror/thiserror-1.0.26.crate" + value: "https://static.crates.io/crates/thiserror/thiserror-1.0.29.crate" } - version: "1.0.26" + version: "1.0.29" license_type: NOTICE last_upgrade_date { year: 2021 - month: 8 - day: 9 + month: 9 + day: 22 } } @@ -137,6 +137,20 @@ pub enum DataStoreError { } ``` +- If a field is both a source (named `source`, or has `#[source]` or `#[from]` + attribute) *and* is marked `#[backtrace]`, then the Error trait's + `backtrace()` method is forwarded to the source's backtrace. + + ```rust + #[derive(Error, Debug)] + pub enum MyError { + Io { + #[backtrace] + source: io::Error, + }, + } + ``` + - Errors may use `error(transparent)` to forward the source and Display methods straight through to an underlying error without adding an additional message. This would be appropriate for enums that need an "anything else" variant. @@ -161,6 +161,22 @@ //! # }; //! ``` //! +//! - If a field is both a source (named `source`, or has `#[source]` or +//! `#[from]` attribute) *and* is marked `#[backtrace]`, then the Error +//! trait's `backtrace()` method is forwarded to the source's backtrace. +//! +//! ```rust +//! # const IGNORE: &str = stringify! { +//! #[derive(Error, Debug)] +//! pub enum MyError { +//! Io { +//! #[backtrace] +//! source: io::Error, +//! }, +//! } +//! # }; +//! ``` +//! //! - Errors may use `error(transparent)` to forward the source and Display //! methods straight through to an underlying error without adding an //! additional message. This would be appropriate for enums that need an diff --git a/tests/test_backtrace.rs b/tests/test_backtrace.rs index c7ba3c4..42e37ca 100644 --- a/tests/test_backtrace.rs +++ b/tests/test_backtrace.rs @@ -1,8 +1,4 @@ #![cfg_attr(thiserror_nightly_testing, feature(backtrace))] -#![allow( - // Clippy bug: https://github.com/rust-lang/rust-clippy/issues/7422 - clippy::nonstandard_macro_braces, -)] use thiserror::Error; @@ -11,8 +7,15 @@ use thiserror::Error; pub struct Inner; #[cfg(thiserror_nightly_testing)] +#[derive(Error, Debug)] +#[error("...")] +pub struct InnerBacktrace { + backtrace: std::backtrace::Backtrace, +} + +#[cfg(thiserror_nightly_testing)] pub mod structs { - use super::Inner; + use super::{Inner, InnerBacktrace}; use std::backtrace::Backtrace; use std::error::Error; use std::sync::Arc; @@ -56,6 +59,14 @@ pub mod structs { #[derive(Error, Debug)] #[error("...")] + pub struct CombinedBacktraceFrom { + #[from] + #[backtrace] + source: InnerBacktrace, + } + + #[derive(Error, Debug)] + #[error("...")] pub struct OptBacktraceFrom { #[from] source: Inner, @@ -97,6 +108,11 @@ pub mod structs { let error = BacktraceFrom::from(Inner); assert!(error.backtrace().is_some()); + let error = CombinedBacktraceFrom::from(InnerBacktrace { + backtrace: Backtrace::capture(), + }); + assert!(error.backtrace().is_some()); + let error = OptBacktraceFrom::from(Inner); assert!(error.backtrace().is_some()); @@ -107,7 +123,7 @@ pub mod structs { #[cfg(thiserror_nightly_testing)] pub mod enums { - use super::Inner; + use super::{Inner, InnerBacktrace}; use std::backtrace::Backtrace; use std::error::Error; use std::sync::Arc; @@ -158,6 +174,16 @@ pub mod enums { } #[derive(Error, Debug)] + pub enum CombinedBacktraceFrom { + #[error("...")] + Test { + #[from] + #[backtrace] + source: InnerBacktrace, + }, + } + + #[derive(Error, Debug)] pub enum OptBacktraceFrom { #[error("...")] Test { @@ -204,6 +230,11 @@ pub mod enums { let error = BacktraceFrom::from(Inner); assert!(error.backtrace().is_some()); + let error = CombinedBacktraceFrom::from(InnerBacktrace { + backtrace: Backtrace::capture(), + }); + assert!(error.backtrace().is_some()); + let error = OptBacktraceFrom::from(Inner); assert!(error.backtrace().is_some()); diff --git a/tests/test_display.rs b/tests/test_display.rs index 8a9ebf7..949d9ed 100644 --- a/tests/test_display.rs +++ b/tests/test_display.rs @@ -1,8 +1,4 @@ #![deny(clippy::all, clippy::pedantic)] -#![allow( - // Clippy bug: https://github.com/rust-lang/rust-clippy/issues/7422 - clippy::nonstandard_macro_braces, -)] use std::fmt::Display; use thiserror::Error; diff --git a/tests/test_expr.rs b/tests/test_expr.rs index 50835a5..87a56cf 100644 --- a/tests/test_expr.rs +++ b/tests/test_expr.rs @@ -1,9 +1,5 @@ #![deny(clippy::all, clippy::pedantic)] -#![allow( - // Clippy bug: https://github.com/rust-lang/rust-clippy/issues/7422 - clippy::nonstandard_macro_braces, - clippy::option_if_let_else, -)] +#![allow(clippy::option_if_let_else)] use std::fmt::Display; use thiserror::Error; diff --git a/tests/test_from.rs b/tests/test_from.rs index b6a3c0c..a25ce35 100644 --- a/tests/test_from.rs +++ b/tests/test_from.rs @@ -1,8 +1,4 @@ #![deny(clippy::all, clippy::pedantic)] -#![allow( - // Clippy bug: https://github.com/rust-lang/rust-clippy/issues/7422 - clippy::nonstandard_macro_braces, -)] use std::io; use thiserror::Error; @@ -16,10 +12,21 @@ pub struct ErrorStruct { #[derive(Error, Debug)] #[error("...")] +pub struct ErrorStructOptional { + #[from] + source: Option<io::Error>, +} + +#[derive(Error, Debug)] +#[error("...")] pub struct ErrorTuple(#[from] io::Error); #[derive(Error, Debug)] #[error("...")] +pub struct ErrorTupleOptional(#[from] Option<io::Error>); + +#[derive(Error, Debug)] +#[error("...")] pub enum ErrorEnum { Test { #[from] @@ -29,6 +36,15 @@ pub enum ErrorEnum { #[derive(Error, Debug)] #[error("...")] +pub enum ErrorEnumOptional { + Test { + #[from] + source: Option<io::Error>, + }, +} + +#[derive(Error, Debug)] +#[error("...")] pub enum Many { Any(#[from] anyhow::Error), Io(#[from] io::Error), @@ -39,7 +55,10 @@ fn assert_impl<T: From<io::Error>>() {} #[test] fn test_from() { assert_impl::<ErrorStruct>(); + assert_impl::<ErrorStructOptional>(); assert_impl::<ErrorTuple>(); + assert_impl::<ErrorTupleOptional>(); assert_impl::<ErrorEnum>(); + assert_impl::<ErrorEnumOptional>(); assert_impl::<Many>(); } diff --git a/tests/test_generics.rs b/tests/test_generics.rs new file mode 100644 index 0000000..f5e1de2 --- /dev/null +++ b/tests/test_generics.rs @@ -0,0 +1,161 @@ +#![deny(clippy::all, clippy::pedantic)] + +use std::fmt::{self, Debug, Display}; +use thiserror::Error; + +pub struct NoFormat; + +#[derive(Debug)] +pub struct DebugOnly; + +pub struct DisplayOnly; + +impl Display for DisplayOnly { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.write_str("display only") + } +} + +#[derive(Debug)] +pub struct DebugAndDisplay; + +impl Display for DebugAndDisplay { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.write_str("debug and display") + } +} + +// Should expand to: +// +// impl<E> Display for EnumDebugField<E> +// where +// E: Debug; +// +// impl<E> Error for EnumDebugField<E> +// where +// Self: Debug + Display; +// +#[derive(Error, Debug)] +pub enum EnumDebugGeneric<E> { + #[error("{0:?}")] + FatalError(E), +} + +// Should expand to: +// +// impl<E> Display for EnumFromGeneric<E>; +// +// impl<E> Error for EnumFromGeneric<E> +// where +// EnumDebugGeneric<E>: Error + 'static, +// Self: Debug + Display; +// +#[derive(Error, Debug)] +pub enum EnumFromGeneric<E> { + #[error("enum from generic")] + Source(#[from] EnumDebugGeneric<E>), +} + +// Should expand to: +// +// impl<HasDisplay, HasDebug, HasNeither> Display +// for EnumCompound<HasDisplay, HasDebug, HasNeither> +// where +// HasDisplay: Display, +// HasDebug: Debug; +// +// impl<HasDisplay, HasDebug, HasNeither> Error +// for EnumCompound<HasDisplay, HasDebug, HasNeither> +// where +// Self: Debug + Display; +// +#[derive(Error)] +pub enum EnumCompound<HasDisplay, HasDebug, HasNeither> { + #[error("{0} {1:?}")] + DisplayDebug(HasDisplay, HasDebug), + #[error("{0}")] + Display(HasDisplay, HasNeither), + #[error("{1:?}")] + Debug(HasNeither, HasDebug), +} + +impl<HasDisplay, HasDebug, HasNeither> Debug for EnumCompound<HasDisplay, HasDebug, HasNeither> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.write_str("EnumCompound") + } +} + +#[test] +fn test_display_enum_compound() { + let mut instance: EnumCompound<DisplayOnly, DebugOnly, NoFormat>; + + instance = EnumCompound::DisplayDebug(DisplayOnly, DebugOnly); + assert_eq!(format!("{}", instance), "display only DebugOnly"); + + instance = EnumCompound::Display(DisplayOnly, NoFormat); + assert_eq!(format!("{}", instance), "display only"); + + instance = EnumCompound::Debug(NoFormat, DebugOnly); + assert_eq!(format!("{}", instance), "DebugOnly"); +} + +// Should expand to: +// +// impl<E> Display for EnumTransparentGeneric<E> +// where +// E: Display; +// +// impl<E> Error for EnumTransparentGeneric<E> +// where +// E: Error, +// Self: Debug + Display; +// +#[derive(Error, Debug)] +pub enum EnumTransparentGeneric<E> { + #[error(transparent)] + Other(E), +} + +// Should expand to: +// +// impl<E> Display for StructDebugGeneric<E> +// where +// E: Debug; +// +// impl<E> Error for StructDebugGeneric<E> +// where +// Self: Debug + Display; +// +#[derive(Error, Debug)] +#[error("{underlying:?}")] +pub struct StructDebugGeneric<E> { + pub underlying: E, +} + +// Should expand to: +// +// impl<E> Error for StructFromGeneric<E> +// where +// StructDebugGeneric<E>: Error + 'static, +// Self: Debug + Display; +// +#[derive(Error, Debug)] +pub struct StructFromGeneric<E> { + #[from] + pub source: StructDebugGeneric<E>, +} + +// Should expand to: +// +// impl<E> Display for StructTransparentGeneric<E> +// where +// E: Display; +// +// impl<E> Error for StructTransparentGeneric<E> +// where +// E: Error, +// Self: Debug + Display; +// +#[derive(Error, Debug)] +#[error(transparent)] +pub struct StructTransparentGeneric<E>(E); diff --git a/tests/test_lints.rs b/tests/test_lints.rs index 457b799..59699a4 100644 --- a/tests/test_lints.rs +++ b/tests/test_lints.rs @@ -1,8 +1,3 @@ -#![allow( - // Clippy bug: https://github.com/rust-lang/rust-clippy/issues/7422 - clippy::nonstandard_macro_braces, -)] - use thiserror::Error; pub use std::error::Error; diff --git a/tests/test_path.rs b/tests/test_path.rs index 777b5de..a10b1f3 100644 --- a/tests/test_path.rs +++ b/tests/test_path.rs @@ -1,8 +1,4 @@ #![deny(clippy::all, clippy::pedantic)] -#![allow( - // Clippy bug: https://github.com/rust-lang/rust-clippy/issues/7422 - clippy::nonstandard_macro_braces, -)] use ref_cast::RefCast; use std::fmt::Display; diff --git a/tests/test_source.rs b/tests/test_source.rs index c7ddda8..ab16097 100644 --- a/tests/test_source.rs +++ b/tests/test_source.rs @@ -1,8 +1,4 @@ #![deny(clippy::all, clippy::pedantic)] -#![allow( - // Clippy bug: https://github.com/rust-lang/rust-clippy/issues/7422 - clippy::nonstandard_macro_braces, -)] use std::error::Error as StdError; use std::io; diff --git a/tests/test_transparent.rs b/tests/test_transparent.rs index 7d02826..84d7c91 100644 --- a/tests/test_transparent.rs +++ b/tests/test_transparent.rs @@ -1,8 +1,4 @@ #![deny(clippy::all, clippy::pedantic)] -#![allow( - // Clippy bug: https://github.com/rust-lang/rust-clippy/issues/7422 - clippy::nonstandard_macro_braces, -)] use anyhow::anyhow; use std::error::Error as _; |