Update thiserror crate to 1.0.49 am: 91e199e0b9 am: a31b7672c8

Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/thiserror/+/2786823

Change-Id: I0fa8a0d51b7a023535223796e23e53c7831d16d6
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/Cargo.toml b/Cargo.toml
index 4d3905b..53b073d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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 @@
 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"]
diff --git a/build.rs b/build.rs
index 004dfb0..7983a2b 100644
--- a/build.rs
+++ b/build.rs
@@ -4,27 +4,56 @@
 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 @@
     }
 }
 
+#[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()
     }
 }
diff --git a/src/lib.rs b/src/lib.rs
index 94bd860..3242c1f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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 @@
 // 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 @@
 #[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 @@
         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 @@
         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 @@
   |
   = 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
   |