]> git.lizzy.rs Git - rust.git/blob - src/test/ui/traits/coercion.rs
Apply suggestions from code review
[rust.git] / src / test / ui / traits / coercion.rs
1 // run-pass
2 #![allow(dead_code)]
3 #![allow(unused_mut)]
4 #![allow(unused_variables)]
5 #![feature(box_syntax)]
6
7 use std::io::{self, Write};
8
9 trait Trait {
10     fn f(&self);
11 }
12
13 #[derive(Copy, Clone)]
14 struct Struct {
15     x: isize,
16     y: isize,
17 }
18
19 impl Trait for Struct {
20     fn f(&self) {
21         println!("Hi!");
22     }
23 }
24
25 fn foo(mut a: Box<dyn Write>) {}
26
27 pub fn main() {
28     let a = Struct { x: 1, y: 2 };
29     let b: Box<dyn Trait> = Box::new(a);
30     b.f();
31     let c: &dyn Trait = &a;
32     c.f();
33
34     let out = io::stdout();
35     foo(Box::new(out));
36 }