diff --git a/src/bin/error_box_provide.rs b/src/bin/error_box_provide.rs new file mode 100644 index 0000000..adaa698 --- /dev/null +++ b/src/bin/error_box_provide.rs @@ -0,0 +1,35 @@ +// https://github.com/rust-lang/rust/issues/117432 + +#![feature(error_generic_member_access)] + +#[derive(Debug)] +struct Foo; + +#[derive(Debug)] +struct MyError { + foo: Foo, +} + +impl std::fmt::Display for MyError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "MyError") + } +} + +impl std::error::Error for MyError { + fn provide<'a>(&'a self, request: &mut std::error::Request<'a>) { + request.provide_ref::(&Foo); + } +} + +fn foo_provided(e: &T) -> bool { + std::error::request_ref::(e).is_some() +} + +fn main() { + let e = MyError { foo: Foo }; + + assert!(foo_provided::(&e)); // ok + assert!(foo_provided::<&MyError>(&&e)); // ok + assert!(foo_provided::>(&Box::new(e))); // fails +}