blob: 11214b310d5096a656e95c9e5b0c8a0a05f2784d [file]
/* { dg-output "123\r*\n123\r*\n" } */
#![feature(no_core)]
#![no_core]
#![feature(lang_items)]
extern "C" {
fn printf(s: *const i8, ...);
}
#[lang = "sized"]
pub trait Sized {}
struct Foo(i32);
trait Bar {
fn baz(&self);
}
impl Bar for Foo {
fn baz(&self) {
unsafe {
let a = "%i\n\0";
let b = a as *const str;
let c = b as *const i8;
printf(c, self.0);
}
}
}
fn static_dispatch<T: Bar>(t: &T) {
t.baz();
}
fn dynamic_dispatch(t: &dyn Bar) {
t.baz();
}
fn main() -> i32 {
let a = &Foo(123);
static_dispatch(a);
let b: &dyn Bar = a;
dynamic_dispatch(b);
0
}