Skip to content

Commit 07acdac

Browse files
authored
Merge pull request #271 from dtolnay/provider
impl std::any::Provider for anyhow::Error
2 parents 916e22b + ee49ec0 commit 07acdac

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

build.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ compile_error! {
1717
const PROBE: &str = r#"
1818
#![feature(error_generic_member_access, provide_any)]
1919
20-
use std::any::Demand;
20+
use std::any::{Demand, Provider};
2121
use std::backtrace::{Backtrace, BacktraceStatus};
2222
use std::error::Error;
2323
use std::fmt::{self, Display};
@@ -39,6 +39,12 @@ const PROBE: &str = r#"
3939
}
4040
}
4141
42+
struct P;
43+
44+
impl Provider for P {
45+
fn provide<'a>(&'a self, _demand: &mut Demand<'a>) {}
46+
}
47+
4248
const _: fn() = || {
4349
let backtrace: Backtrace = Backtrace::capture();
4450
let status: BacktraceStatus = backtrace.status();

src/error.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -522,15 +522,16 @@ impl Error {
522522
Some(addr.cast::<E>().deref_mut())
523523
}
524524
}
525+
}
525526

527+
#[cfg(backtrace)]
528+
impl std::any::Provider for Error {
526529
// Called by thiserror when you have `#[source] anyhow::Error`. This provide
527530
// implementation includes the anyhow::Error's Backtrace if any, unlike
528531
// deref'ing to dyn Error where the provide implementation would include
529532
// only the original error's Backtrace from before it got wrapped into an
530533
// anyhow::Error.
531-
#[cfg(backtrace)]
532-
#[doc(hidden)]
533-
pub fn provide<'a>(&'a self, demand: &mut Demand<'a>) {
534+
fn provide<'a>(&'a self, demand: &mut Demand<'a>) {
534535
unsafe { ErrorImpl::provide(self.inner.by_ref(), demand) }
535536
}
536537
}

0 commit comments

Comments
 (0)