2013-09-16 08:05:47 -05:00
|
|
|
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
#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
|
|
|
}
|
|
|
|
|
|
|
|
fn print_name(x: &Debuggable)
|
|
|
|
{
|
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();
|
|
|
|
print_name(&thing as &Debuggable);
|
|
|
|
}
|