Skip to content

Commit

Permalink
add rust-lang/rust#117432 reproduce
Browse files Browse the repository at this point in the history
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
  • Loading branch information
BugenZhao committed Oct 31, 2023
1 parent 4f821e7 commit 0f961fe
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/bin/error_box_provide.rs
Original file line number Diff line number Diff line change
@@ -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>(&Foo);
}
}

fn foo_provided<T: std::error::Error>(e: &T) -> bool {
std::error::request_ref::<Foo>(e).is_some()
}

fn main() {
let e = MyError { foo: Foo };

assert!(foo_provided::<MyError>(&e)); // ok
assert!(foo_provided::<&MyError>(&&e)); // ok
assert!(foo_provided::<Box<MyError>>(&Box::new(e))); // fails
}

0 comments on commit 0f961fe

Please sign in to comment.