| 1 |
/* { dg-output "123\r*\n456\r*\n" } */ |
| 2 |
extern "C" { |
| 3 |
fn printf(s: *const i8, ...); |
| 4 |
} |
| 5 |
|
| 6 |
#[lang = "sized"] |
| 7 |
pub trait Sized {} |
| 8 |
|
| 9 |
struct Foo(i32); |
| 10 |
trait Bar { |
| 11 |
fn baz(&self); |
| 12 |
|
| 13 |
fn qux(&self) { |
| 14 |
// { dg-warning "unused name" "" { target *-*-* } .-1 } |
| 15 |
unsafe { |
| 16 |
let a = "%i\n\0"; |
| 17 |
let b = a as *const str; |
| 18 |
let c = b as *const i8; |
| 19 |
|
| 20 |
printf(c, 456); |
| 21 |
} |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
impl Bar for Foo { |
| 26 |
fn baz(&self) { |
| 27 |
unsafe { |
| 28 |
let a = "%i\n\0"; |
| 29 |
let b = a as *const str; |
| 30 |
let c = b as *const i8; |
| 31 |
|
| 32 |
printf(c, self.0); |
| 33 |
} |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
fn dynamic_dispatch(t: &dyn Bar) { |
| 38 |
t.baz(); |
| 39 |
t.qux(); |
| 40 |
} |
| 41 |
|
| 42 |
fn main() -> i32 { |
| 43 |
let a; |
| 44 |
a = Foo(123); |
| 45 |
|
| 46 |
let b: &dyn Bar; |
| 47 |
b = &a; |
| 48 |
dynamic_dispatch(b); |
| 49 |
|
| 50 |
0 |
| 51 |
} |