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