From b7448d3ad68f60beb79b2833afe43f4ef7c2825d Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Wed, 7 Sep 2022 22:01:15 -0700 Subject: [PATCH 1/2] impl std::any::Provider for anyhow::Error --- src/error.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/error.rs b/src/error.rs index d707297..9f6ce8c 100644 --- a/src/error.rs +++ b/src/error.rs @@ -522,15 +522,16 @@ impl Error { Some(addr.cast::().deref_mut()) } } +} +#[cfg(backtrace)] +impl std::any::Provider for Error { // Called by thiserror when you have `#[source] anyhow::Error`. This provide // implementation includes the anyhow::Error's Backtrace if any, unlike // deref'ing to dyn Error where the provide implementation would include // only the original error's Backtrace from before it got wrapped into an // anyhow::Error. - #[cfg(backtrace)] - #[doc(hidden)] - pub fn provide<'a>(&'a self, demand: &mut Demand<'a>) { + fn provide<'a>(&'a self, demand: &mut Demand<'a>) { unsafe { ErrorImpl::provide(self.inner.by_ref(), demand) } } } From ee49ec0d49049fcbe99c7d7940e85b6b085a8eaa Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 13 Sep 2022 11:51:11 -0700 Subject: [PATCH 2/2] Add impl Provider in build.rs probe --- build.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/build.rs b/build.rs index 7bfdca1..3800683 100644 --- a/build.rs +++ b/build.rs @@ -17,7 +17,7 @@ compile_error! { const PROBE: &str = r#" #![feature(error_generic_member_access, provide_any)] - use std::any::Demand; + use std::any::{Demand, Provider}; use std::backtrace::{Backtrace, BacktraceStatus}; use std::error::Error; use std::fmt::{self, Display}; @@ -39,6 +39,12 @@ const PROBE: &str = r#" } } + struct P; + + impl Provider for P { + fn provide<'a>(&'a self, _demand: &mut Demand<'a>) {} + } + const _: fn() = || { let backtrace: Backtrace = Backtrace::capture(); let status: BacktraceStatus = backtrace.status();