diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-07-07 04:55:54 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-07-07 04:55:54 +0000 |
commit | 5600440aba13c691efb341a444955ad656b3f16e (patch) | |
tree | d78b715926d3c0eebd4a55fa04a90b1f02dc212e | |
parent | d053dc6234c0cf26ba2a43bf58cb4ee1295e3d53 (diff) | |
parent | 3948acbfd8f486638f13cfc94a9035dbc5cdc2a7 (diff) | |
download | thiserror-impl-aml_ips_341611000.tar.gz |
Snap for 10453563 from 3948acbfd8f486638f13cfc94a9035dbc5cdc2a7 to mainline-ipsec-releaseaml_ips_341611000aml_ips_341510000aml_ips_340914280aml_ips_340914200aml_ips_340914000
Change-Id: I860d99531b40cb10d4504cc6fd2446bf07709621
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | Android.bp | 4 | ||||
-rw-r--r-- | Cargo.toml | 4 | ||||
-rw-r--r-- | Cargo.toml.orig | 6 | ||||
-rw-r--r-- | METADATA | 12 | ||||
-rw-r--r-- | TEST_MAPPING | 118 | ||||
-rw-r--r-- | src/expand.rs | 108 | ||||
-rw-r--r-- | src/generics.rs | 1 | ||||
-rw-r--r-- | src/lib.rs | 5 | ||||
-rw-r--r-- | src/valid.rs | 6 |
10 files changed, 112 insertions, 154 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index 2d04484..9f6267f 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,6 +1,6 @@ { "git": { - "sha1": "672e9525bbc2e5682c380d36974f34716b963591" + "sha1": "74bfe75eb25ba9d39b0ae5b570d611855cbc5086" }, "path_in_vcs": "impl" }
\ No newline at end of file @@ -43,7 +43,7 @@ rust_proc_macro { name: "libthiserror_impl", crate_name: "thiserror_impl", cargo_env_compat: true, - cargo_pkg_version: "1.0.30", + cargo_pkg_version: "1.0.38", srcs: ["src/lib.rs"], edition: "2018", rustlibs: [ @@ -51,4 +51,6 @@ rust_proc_macro { "libquote", "libsyn", ], + product_available: true, + vendor_available: true, } @@ -13,16 +13,18 @@ edition = "2018" rust-version = "1.31" name = "thiserror-impl" -version = "1.0.30" +version = "1.0.38" authors = ["David Tolnay <dtolnay@gmail.com>"] description = "Implementation detail of the `thiserror` crate" license = "MIT OR Apache-2.0" repository = "https://github.com/dtolnay/thiserror" + [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] [lib] proc-macro = true + [dependencies.proc-macro2] version = "1.0" diff --git a/Cargo.toml.orig b/Cargo.toml.orig index e2ad11b..dee506a 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,12 +1,12 @@ [package] name = "thiserror-impl" -version = "1.0.30" +version = "1.0.38" authors = ["David Tolnay <dtolnay@gmail.com>"] +description = "Implementation detail of the `thiserror` crate" edition = "2018" -rust-version = "1.31" license = "MIT OR Apache-2.0" -description = "Implementation detail of the `thiserror` crate" repository = "https://github.com/dtolnay/thiserror" +rust-version = "1.31" [lib] proc-macro = true @@ -1,3 +1,7 @@ +# This project was upgraded with external_updater. +# Usage: tools/external_updater/updater.sh update rust/crates/thiserror-impl +# For more info, check https://cs.android.com/android/platform/superproject/+/master:tools/external_updater/README.md + name: "thiserror-impl" description: "Implementation detail of the `thiserror` crate" third_party { @@ -7,13 +11,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/thiserror-impl/thiserror-impl-1.0.30.crate" + value: "https://static.crates.io/crates/thiserror-impl/thiserror-impl-1.0.38.crate" } - version: "1.0.30" + version: "1.0.38" license_type: NOTICE last_upgrade_date { year: 2022 - month: 3 - day: 1 + month: 12 + day: 19 } } diff --git a/TEST_MAPPING b/TEST_MAPPING index eea7991..6b4c996 100644 --- a/TEST_MAPPING +++ b/TEST_MAPPING @@ -9,142 +9,60 @@ }, { "path": "external/rust/crates/serde-xml-rs" - } - ], - "presubmit": [ - { - "name": "ZipFuseTest" - }, - { - "name": "apkdmverity.test" - }, - { - "name": "authfs_device_test_src_lib" - }, - { - "name": "diced_open_dice_cbor_test" - }, - { - "name": "diced_sample_inputs_test" - }, - { - "name": "diced_test" - }, - { - "name": "diced_utils_test" - }, - { - "name": "diced_vendor_test" - }, - { - "name": "doh_unit_test" - }, - { - "name": "keystore2_crypto_test_rust" - }, - { - "name": "keystore2_selinux_concurrency_test" - }, - { - "name": "keystore2_selinux_test" - }, - { - "name": "keystore2_test" - }, - { - "name": "keystore2_test_utils_test" - }, - { - "name": "keystore2_vintf_test" - }, - { - "name": "legacykeystore_test" - }, - { - "name": "libapkverify.integration_test" - }, - { - "name": "libapkverify.test" - }, - { - "name": "libcert_request_validator_tests" - }, - { - "name": "librustutils_test" - }, - { - "name": "microdroid_manager_test" - }, - { - "name": "virtualizationservice_device_test" - } - ], - "presubmit-rust": [ - { - "name": "ZipFuseTest" - }, - { - "name": "apkdmverity.test" - }, - { - "name": "authfs_device_test_src_lib" - }, - { - "name": "diced_open_dice_cbor_test" }, { - "name": "diced_sample_inputs_test" + "path": "external/uwb/src" }, { - "name": "diced_test" + "path": "packages/modules/DnsResolver" }, { - "name": "diced_utils_test" + "path": "packages/modules/Virtualization/apkdmverity" }, { - "name": "diced_vendor_test" + "path": "packages/modules/Virtualization/authfs" }, { - "name": "doh_unit_test" + "path": "packages/modules/Virtualization/avmd" }, { - "name": "keystore2_crypto_test_rust" + "path": "packages/modules/Virtualization/encryptedstore" }, { - "name": "keystore2_selinux_concurrency_test" + "path": "packages/modules/Virtualization/libs/apexutil" }, { - "name": "keystore2_selinux_test" + "path": "packages/modules/Virtualization/libs/devicemapper" }, { - "name": "keystore2_test" + "path": "packages/modules/Virtualization/microdroid_manager" }, { - "name": "keystore2_test_utils_test" + "path": "packages/modules/Virtualization/virtualizationmanager" }, { - "name": "keystore2_vintf_test" + "path": "packages/modules/Virtualization/vm" }, { - "name": "legacykeystore_test" + "path": "packages/modules/Virtualization/zipfuse" }, { - "name": "libapkverify.integration_test" + "path": "system/keymint/hal" }, { - "name": "libapkverify.test" + "path": "system/security/diced" }, { - "name": "libcert_request_validator_tests" + "path": "system/security/keystore2" }, { - "name": "librustutils_test" + "path": "system/security/keystore2/legacykeystore" }, { - "name": "microdroid_manager_test" + "path": "system/security/keystore2/selinux" }, { - "name": "virtualizationservice_device_test" + "path": "system/security/keystore2/src/crypto" } ] } diff --git a/src/expand.rs b/src/expand.rs index 435ad48..4352209 100644 --- a/src/expand.rs +++ b/src/expand.rs @@ -53,51 +53,59 @@ fn impl_struct(input: Struct) -> TokenStream { let source_method = source_body.map(|body| { quote! { fn source(&self) -> std::option::Option<&(dyn std::error::Error + 'static)> { - use thiserror::private::AsDynError; + use thiserror::__private::AsDynError; #body } } }); - let backtrace_method = input.backtrace_field().map(|backtrace_field| { + let provide_method = input.backtrace_field().map(|backtrace_field| { + let demand = quote!(demand); let backtrace = &backtrace_field.member; let body = if let Some(source_field) = input.source_field() { let source = &source_field.member; - let source_backtrace = if type_is_option(source_field.ty) { + let source_provide = if type_is_option(source_field.ty) { quote_spanned! {source.span()=> - self.#source.as_ref().and_then(|source| source.as_dyn_error().backtrace()) + if let std::option::Option::Some(source) = &self.#source { + source.thiserror_provide(#demand); + } } } else { quote_spanned! {source.span()=> - self.#source.as_dyn_error().backtrace() + self.#source.thiserror_provide(#demand); } }; - let combinator = if source == backtrace { - source_backtrace + let self_provide = if source == backtrace { + None } else if type_is_option(backtrace_field.ty) { - quote! { - #source_backtrace.or(self.#backtrace.as_ref()) - } + Some(quote! { + if let std::option::Option::Some(backtrace) = &self.#backtrace { + #demand.provide_ref::<std::backtrace::Backtrace>(backtrace); + } + }) } else { - quote! { - std::option::Option::Some(#source_backtrace.unwrap_or(&self.#backtrace)) - } + Some(quote! { + #demand.provide_ref::<std::backtrace::Backtrace>(&self.#backtrace); + }) }; quote! { - use thiserror::private::AsDynError; - #combinator + use thiserror::__private::ThiserrorProvide; + #source_provide + #self_provide } } else if type_is_option(backtrace_field.ty) { quote! { - self.#backtrace.as_ref() + if let std::option::Option::Some(backtrace) = &self.#backtrace { + #demand.provide_ref::<std::backtrace::Backtrace>(backtrace); + } } } else { quote! { - std::option::Option::Some(&self.#backtrace) + #demand.provide_ref::<std::backtrace::Backtrace>(&self.#backtrace); } }; quote! { - fn backtrace(&self) -> std::option::Option<&std::backtrace::Backtrace> { + fn provide<'_demand>(&'_demand self, #demand: &mut std::any::Demand<'_demand>) { #body } } @@ -115,7 +123,7 @@ fn impl_struct(input: Struct) -> TokenStream { let use_as_display = if display.has_bonus_display { Some(quote! { #[allow(unused_imports)] - use thiserror::private::{DisplayAsDisplay, PathAsDisplay}; + use thiserror::__private::{DisplayAsDisplay, PathAsDisplay}; }) } else { None @@ -177,7 +185,7 @@ fn impl_struct(input: Struct) -> TokenStream { #[allow(unused_qualifications)] impl #impl_generics #error_trait for #ty #ty_generics #error_where_clause { #source_method - #backtrace_method + #provide_method } #display_impl #from_impl @@ -226,7 +234,7 @@ fn impl_enum(input: Enum) -> TokenStream { }); Some(quote! { fn source(&self) -> std::option::Option<&(dyn std::error::Error + 'static)> { - use thiserror::private::AsDynError; + use thiserror::__private::AsDynError; #[allow(deprecated)] match self { #(#arms)* @@ -237,7 +245,8 @@ fn impl_enum(input: Enum) -> TokenStream { None }; - let backtrace_method = if input.has_backtrace() { + let provide_method = if input.has_backtrace() { + let demand = quote!(demand); let arms = input.variants.iter().map(|variant| { let ident = &variant.ident; match (variant.backtrace_field(), variant.source_field()) { @@ -247,22 +256,26 @@ fn impl_enum(input: Enum) -> TokenStream { let backtrace = &backtrace_field.member; let source = &source_field.member; let varsource = quote!(source); - let source_backtrace = if type_is_option(source_field.ty) { + let source_provide = if type_is_option(source_field.ty) { quote_spanned! {source.span()=> - #varsource.as_ref().and_then(|source| source.as_dyn_error().backtrace()) + if let std::option::Option::Some(source) = #varsource { + source.thiserror_provide(#demand); + } } } else { quote_spanned! {source.span()=> - #varsource.as_dyn_error().backtrace() + #varsource.thiserror_provide(#demand); } }; - let combinator = if type_is_option(backtrace_field.ty) { + let self_provide = if type_is_option(backtrace_field.ty) { quote! { - #source_backtrace.or(backtrace.as_ref()) + if let std::option::Option::Some(backtrace) = backtrace { + #demand.provide_ref::<std::backtrace::Backtrace>(backtrace); + } } } else { quote! { - std::option::Option::Some(#source_backtrace.unwrap_or(backtrace)) + #demand.provide_ref::<std::backtrace::Backtrace>(backtrace); } }; quote! { @@ -271,8 +284,9 @@ fn impl_enum(input: Enum) -> TokenStream { #source: #varsource, .. } => { - use thiserror::private::AsDynError; - #combinator + use thiserror::__private::ThiserrorProvide; + #source_provide + #self_provide } } } @@ -281,40 +295,50 @@ fn impl_enum(input: Enum) -> TokenStream { { let backtrace = &backtrace_field.member; let varsource = quote!(source); - let source_backtrace = if type_is_option(source_field.ty) { + let source_provide = if type_is_option(source_field.ty) { quote_spanned! {backtrace.span()=> - #varsource.as_ref().and_then(|source| source.as_dyn_error().backtrace()) + if let std::option::Option::Some(source) = #varsource { + source.thiserror_provide(#demand); + } } } else { quote_spanned! {backtrace.span()=> - #varsource.as_dyn_error().backtrace() + #varsource.thiserror_provide(#demand); } }; quote! { #ty::#ident {#backtrace: #varsource, ..} => { - use thiserror::private::AsDynError; - #source_backtrace + use thiserror::__private::ThiserrorProvide; + #source_provide } } } (Some(backtrace_field), _) => { let backtrace = &backtrace_field.member; let body = if type_is_option(backtrace_field.ty) { - quote!(backtrace.as_ref()) + quote! { + if let std::option::Option::Some(backtrace) = backtrace { + #demand.provide_ref::<std::backtrace::Backtrace>(backtrace); + } + } } else { - quote!(std::option::Option::Some(backtrace)) + quote! { + #demand.provide_ref::<std::backtrace::Backtrace>(backtrace); + } }; quote! { - #ty::#ident {#backtrace: backtrace, ..} => #body, + #ty::#ident {#backtrace: backtrace, ..} => { + #body + } } } (None, _) => quote! { - #ty::#ident {..} => std::option::Option::None, + #ty::#ident {..} => {} }, } }); Some(quote! { - fn backtrace(&self) -> std::option::Option<&std::backtrace::Backtrace> { + fn provide<'_demand>(&'_demand self, #demand: &mut std::any::Demand<'_demand>) { #[allow(deprecated)] match self { #(#arms)* @@ -335,7 +359,7 @@ fn impl_enum(input: Enum) -> TokenStream { }) { Some(quote! { #[allow(unused_imports)] - use thiserror::private::{DisplayAsDisplay, PathAsDisplay}; + use thiserror::__private::{DisplayAsDisplay, PathAsDisplay}; }) } else { None @@ -420,7 +444,7 @@ fn impl_enum(input: Enum) -> TokenStream { #[allow(unused_qualifications)] impl #impl_generics #error_trait for #ty #ty_generics #error_where_clause { #source_method - #backtrace_method + #provide_method } #display_impl #(#from_impls)* diff --git a/src/generics.rs b/src/generics.rs index 254c2ed..95592a7 100644 --- a/src/generics.rs +++ b/src/generics.rs @@ -57,6 +57,7 @@ impl InferredBounds { } } + #[allow(clippy::type_repetition_in_bounds, clippy::trait_duplication_in_bounds)] // clippy bug: https://github.com/rust-lang/rust-clippy/issues/8771 pub fn insert(&mut self, ty: impl ToTokens, bound: impl ToTokens) { let ty = ty.to_token_stream(); let bound = bound.to_token_stream(); @@ -1,13 +1,16 @@ #![allow( clippy::blocks_in_if_conditions, + clippy::cast_lossless, clippy::cast_possible_truncation, + clippy::manual_find, clippy::manual_map, clippy::map_unwrap_or, clippy::needless_pass_by_value, clippy::option_if_let_else, clippy::range_plus_one, clippy::single_match_else, - clippy::too_many_lines + clippy::too_many_lines, + clippy::wrong_self_convention )] extern crate proc_macro; diff --git a/src/valid.rs b/src/valid.rs index 7657265..cf5b859 100644 --- a/src/valid.rs +++ b/src/valid.rs @@ -180,7 +180,11 @@ fn check_field_attrs(fields: &[Field]) -> Result<()> { } } if let Some(from_field) = from_field { - if fields.len() > 1 + has_backtrace as usize { + let max_expected_fields = match backtrace_field { + Some(backtrace_field) => 1 + !same_member(from_field, backtrace_field) as usize, + None => 1 + has_backtrace as usize, + }; + if fields.len() > max_expected_fields { return Err(Error::new_spanned( from_field.attrs.from, "deriving From requires no fields other than source and backtrace", |