Skip to content

Commit

Permalink
impl std::any::Provider for anyhow::Error
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Sep 13, 2022
1 parent 916e22b commit b7448d3
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,15 +522,16 @@ impl Error {
Some(addr.cast::<E>().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) }
}
}
Expand Down

0 comments on commit b7448d3

Please sign in to comment.