2018-08-30 12:18:55 +00:00
|
|
|
//@ run-pass
|
2013-09-16 13:05:47 +00:00
|
|
|
/*
|
|
|
|
|
|
|
|
#5008 cast to &Trait causes code to segfault on method call
|
|
|
|
|
|
|
|
It fixes itself if the &Trait is changed to @Trait.
|
|
|
|
*/
|
|
|
|
|
|
|
|
trait Debuggable {
|
2014-05-22 23:57:53 +00:00
|
|
|
fn debug_name(&self) -> String;
|
2013-09-16 13:05:47 +00:00
|
|
|
}
|
|
|
|
|
2014-12-31 04:32:49 +00:00
|
|
|
#[derive(Clone)]
|
2013-09-16 13:05:47 +00:00
|
|
|
struct Thing {
|
2014-05-22 23:57:53 +00:00
|
|
|
name: String,
|
2013-09-16 13:05:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Thing {
|
2014-05-25 10:17:19 +00:00
|
|
|
fn new() -> Thing { Thing { name: "dummy".to_string() } }
|
2013-09-16 13:05:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Debuggable for Thing {
|
2014-05-22 23:57:53 +00:00
|
|
|
fn debug_name(&self) -> String { self.name.clone() }
|
2013-09-16 13:05:47 +00:00
|
|
|
}
|
|
|
|
|
2019-05-28 18:47:21 +00:00
|
|
|
fn print_name(x: &dyn Debuggable)
|
2013-09-16 13:05:47 +00:00
|
|
|
{
|
2013-09-30 02:23:57 +00:00
|
|
|
println!("debug_name = {}", x.debug_name());
|
2013-09-16 13:05:47 +00:00
|
|
|
}
|
|
|
|
|
2013-09-25 07:43:37 +00:00
|
|
|
pub fn main() {
|
2013-09-16 13:05:47 +00:00
|
|
|
let thing = Thing::new();
|
2019-05-28 18:47:21 +00:00
|
|
|
print_name(&thing as &dyn Debuggable);
|
2013-09-16 13:05:47 +00:00
|
|
|
}
|