-
Notifications
You must be signed in to change notification settings - Fork 5
/
0005-failure.rs
57 lines (48 loc) · 1.01 KB
/
0005-failure.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*!
```rudra-poc
[target]
crate = "failure"
version = "0.1.8"
[report]
issue_url = "https://github.com/rust-lang-nursery/failure/issues/336"
issue_date = 2019-11-13
rustsec_url = "https://github.com/RustSec/advisory-db/pull/318"
rustsec_id = "RUSTSEC-2019-0036"
[[bugs]]
analyzer = "Manual"
bug_class = "Other"
rudra_report_locations = []
```
!*/
#![forbid(unsafe_code)]
use std::any::TypeId;
use std::fmt::{self, Display};
use failure::Fail;
#[derive(Debug)]
struct Error1 {
name: String,
}
impl Display for Error1 {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Error1 ({})", self.name)
}
}
impl Fail for Error1 {
fn __private_get_type_id__(&self) -> TypeId {
TypeId::of::<Error2>()
}
}
#[derive(Debug, Fail)]
#[fail(display = "Error2")]
struct Error2 {
p1: usize,
p2: usize,
p3: usize,
}
fn main() {
let e1: Box<dyn Fail> = Box::new(Error1 {
name: "test".to_owned(),
});
let e2: Option<&Error2> = e1.downcast_ref();
dbg!(e2);
}