]>
Commit | Line | Data |
---|---|---|
b7449926 | 1 | // run-pass |
1a4d82fc JJ |
2 | /* |
3 | ||
4 | #5008 cast to &Trait causes code to segfault on method call | |
5 | ||
6 | It fixes itself if the &Trait is changed to @Trait. | |
7 | */ | |
8 | ||
9 | trait Debuggable { | |
10 | fn debug_name(&self) -> String; | |
11 | } | |
12 | ||
13 | #[derive(Clone)] | |
14 | struct Thing { | |
15 | name: String, | |
16 | } | |
17 | ||
18 | impl Thing { | |
19 | fn new() -> Thing { Thing { name: "dummy".to_string() } } | |
20 | } | |
21 | ||
22 | impl Debuggable for Thing { | |
23 | fn debug_name(&self) -> String { self.name.clone() } | |
24 | } | |
25 | ||
dc9dc135 | 26 | fn print_name(x: &dyn Debuggable) |
1a4d82fc JJ |
27 | { |
28 | println!("debug_name = {}", x.debug_name()); | |
29 | } | |
30 | ||
31 | pub fn main() { | |
32 | let thing = Thing::new(); | |
dc9dc135 | 33 | print_name(&thing as &dyn Debuggable); |
1a4d82fc | 34 | } |