2018-08-30 07:18:55 -05:00
|
|
|
// run-pass
|
2013-09-16 08:05:47 -05: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 18:57:53 -05:00
|
|
|
fn debug_name(&self) -> String;
|
2013-09-16 08:05:47 -05:00
|
|
|
}
|
|
|
|
|
2014-12-30 22:32:49 -06:00
|
|
|
#[derive(Clone)]
|
2013-09-16 08:05:47 -05:00
|
|
|
struct Thing {
|
2014-05-22 18:57:53 -05:00
|
|
|
name: String,
|
2013-09-16 08:05:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Thing {
|
2014-05-25 05:17:19 -05:00
|
|
|
fn new() -> Thing { Thing { name: "dummy".to_string() } }
|
2013-09-16 08:05:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Debuggable for Thing {
|
2014-05-22 18:57:53 -05:00
|
|
|
fn debug_name(&self) -> String { self.name.clone() }
|
2013-09-16 08:05:47 -05:00
|
|
|
}
|
|
|
|
|
2019-05-28 13:47:21 -05:00
|
|
|
fn print_name(x: &dyn Debuggable)
|
2013-09-16 08:05:47 -05:00
|
|
|
{
|
2013-09-29 21:23:57 -05:00
|
|
|
println!("debug_name = {}", x.debug_name());
|
2013-09-16 08:05:47 -05:00
|
|
|
}
|
|
|
|
|
2013-09-25 02:43:37 -05:00
|
|
|
pub fn main() {
|
2013-09-16 08:05:47 -05:00
|
|
|
let thing = Thing::new();
|
2019-05-28 13:47:21 -05:00
|
|
|
print_name(&thing as &dyn Debuggable);
|
2013-09-16 08:05:47 -05:00
|
|
|
}
|