Upgrade thiserror-impl to 1.0.38

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

Test: TreeHugger
Change-Id: Ic055a3d12eaf5b2ebd0530c997b96d4b983573fa
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
diff --git a/Android.bp b/Android.bp
index d3c9ef4..f63b1c1 100644
--- a/Android.bp
+++ b/Android.bp
@@ -43,7 +43,7 @@
     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: [
diff --git a/Cargo.toml b/Cargo.toml
index 97e0042..ca2a0b4 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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>"]
-edition = "2018"
-rust-version = "1.31"
-license = "MIT OR Apache-2.0"
 description = "Implementation detail of the `thiserror` crate"
+edition = "2018"
+license = "MIT OR Apache-2.0"
 repository = "https://github.com/dtolnay/thiserror"
+rust-version = "1.31"
 
 [lib]
 proc-macro = true
diff --git a/METADATA b/METADATA
index 594ab80..075ed9f 100644
--- a/METADATA
+++ b/METADATA
@@ -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 @@
   }
   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/src/expand.rs b/src/expand.rs
index 435ad48..4352209 100644
--- a/src/expand.rs
+++ b/src/expand.rs
@@ -53,51 +53,59 @@
     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 @@
         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 @@
         #[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 @@
         });
         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 @@
         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 @@
                     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 @@
                             #source: #varsource,
                             ..
                         } => {
-                            use thiserror::private::AsDynError;
-                            #combinator
+                            use thiserror::__private::ThiserrorProvide;
+                            #source_provide
+                            #self_provide
                         }
                     }
                 }
@@ -281,40 +295,50 @@
                 {
                     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 @@
         }) {
             Some(quote! {
                 #[allow(unused_imports)]
-                use thiserror::private::{DisplayAsDisplay, PathAsDisplay};
+                use thiserror::__private::{DisplayAsDisplay, PathAsDisplay};
             })
         } else {
             None
@@ -420,7 +444,7 @@
         #[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 @@
         }
     }
 
+    #[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();
diff --git a/src/lib.rs b/src/lib.rs
index a4d5ae7..f0fc969 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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 @@
         }
     }
     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",