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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

33 lines
408 B
Rust
Raw Normal View History

// run-pass
#![allow(dead_code)]
2012-12-06 20:32:13 -06:00
trait T {
fn print(&self);
}
2015-01-28 07:34:18 -06:00
#[derive(Debug)]
2012-12-06 20:32:13 -06:00
struct S {
s: isize,
2012-12-06 20:32:13 -06:00
}
impl T for S {
2012-12-06 20:32:13 -06:00
fn print(&self) {
println!("{:?}", self);
2012-12-06 20:32:13 -06:00
}
}
2019-05-28 13:47:21 -05:00
fn print_t(t: &dyn T) {
2012-12-06 20:32:13 -06: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 13:47:21 -05:00
let t: Box<dyn T> = s as Box<dyn T>;
print_t(&*t);
2012-12-06 20:32:13 -06:00
}