rust/tests/ui/coercion/issue-3794.rs

33 lines
409 B
Rust
Raw Normal View History

//@ run-pass
#![allow(dead_code)]
2012-12-07 02:32:13 +00:00
trait T {
fn print(&self);
}
2015-01-28 13:34:18 +00:00
#[derive(Debug)]
2012-12-07 02:32:13 +00:00
struct S {
s: isize,
2012-12-07 02:32:13 +00:00
}
impl T for S {
2012-12-07 02:32:13 +00:00
fn print(&self) {
println!("{:?}", self);
2012-12-07 02:32:13 +00:00
}
}
2019-05-28 18:47:21 +00:00
fn print_t(t: &dyn T) {
2012-12-07 02:32:13 +00:00
t.print();
}
fn print_s(s: &S) {
s.print();
}
pub fn main() {
let s: Box<S> = Box::new(S { s: 5 });
print_s(&*s);
2019-05-28 18:47:21 +00:00
let t: Box<dyn T> = s as Box<dyn T>;
print_t(&*t);
2012-12-07 02:32:13 +00:00
}