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