| 1 |
/* { dg-output "parent123\r*\nchild\r*\n" } */ |
| 2 |
//Testing lifetimes with supertraits |
| 3 |
|
| 4 |
extern "C" { |
| 5 |
fn printf(s: *const i8, ...); |
| 6 |
} |
| 7 |
|
| 8 |
struct Foo { |
| 9 |
my_int: u32, |
| 10 |
} |
| 11 |
|
| 12 |
trait Parent { |
| 13 |
fn parent(&self); |
| 14 |
} |
| 15 |
|
| 16 |
trait Child : Parent { |
| 17 |
fn child(&self); |
| 18 |
} |
| 19 |
|
| 20 |
impl Parent for Foo { |
| 21 |
fn parent(&self) { |
| 22 |
unsafe { |
| 23 |
let parent = "parent%i\n\0"; |
| 24 |
let msg = parent as *const str; |
| 25 |
printf(msg as *const i8,self.my_int); |
| 26 |
return; |
| 27 |
} |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
impl Child for Foo { |
| 32 |
fn child<'a>(&self) { |
| 33 |
let _ = self; |
| 34 |
unsafe { |
| 35 |
let child = "child\n\0"; |
| 36 |
let msg = child as *const str; |
| 37 |
printf(msg as *const i8); |
| 38 |
} |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
pub fn main() -> i32 { |
| 43 |
let a = Foo{ my_int: 123}; |
| 44 |
let b: &dyn Child = &a; |
| 45 |
|
| 46 |
b.parent(); |
| 47 |
b.child(); |
| 48 |
|
| 49 |
let _ = a.my_int; |
| 50 |
|
| 51 |
0 |
| 52 |
} |