]> git.proxmox.com Git - rustc.git/blame - src/test/ui/issues/issue-5008-borrowed-traitobject-method-call.rs
New upstream version 1.48.0~beta.8+dfsg1
[rustc.git] / src / test / ui / issues / issue-5008-borrowed-traitobject-method-call.rs
CommitLineData
b7449926 1// run-pass
1a4d82fc
JJ
2/*
3
4#5008 cast to &Trait causes code to segfault on method call
5
6It fixes itself if the &Trait is changed to @Trait.
7*/
8
9trait Debuggable {
10 fn debug_name(&self) -> String;
11}
12
13#[derive(Clone)]
14struct Thing {
15 name: String,
16}
17
18impl Thing {
19 fn new() -> Thing { Thing { name: "dummy".to_string() } }
20}
21
22impl Debuggable for Thing {
23 fn debug_name(&self) -> String { self.name.clone() }
24}
25
dc9dc135 26fn print_name(x: &dyn Debuggable)
1a4d82fc
JJ
27{
28 println!("debug_name = {}", x.debug_name());
29}
30
31pub fn main() {
32 let thing = Thing::new();
dc9dc135 33 print_name(&thing as &dyn Debuggable);
1a4d82fc 34}