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