rust/tests/ui/traits/coercion.rs

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

36 lines
525 B
Rust
Raw Normal View History

//@ run-pass
#![allow(dead_code)]
#![allow(unused_mut)]
#![allow(unused_variables)]
use std::io::{self, Write};
2013-12-27 05:38:28 +00:00
trait Trait {
fn f(&self);
}
2015-03-30 13:38:27 +00:00
#[derive(Copy, Clone)]
2013-12-27 05:38:28 +00:00
struct Struct {
x: isize,
y: isize,
2013-12-27 05:38:28 +00:00
}
impl Trait for Struct {
fn f(&self) {
println!("Hi!");
2013-12-27 05:38:28 +00:00
}
}
2019-05-28 18:47:21 +00:00
fn foo(mut a: Box<dyn Write>) {}
2013-12-27 05:38:28 +00:00
pub fn main() {
let a = Struct { x: 1, y: 2 };
2019-05-28 18:47:21 +00:00
let b: Box<dyn Trait> = Box::new(a);
2013-12-27 05:38:28 +00:00
b.f();
2019-05-28 18:47:21 +00:00
let c: &dyn Trait = &a;
2013-12-27 05:38:28 +00:00
c.f();
let out = io::stdout();
foo(Box::new(out));
2013-12-27 05:38:28 +00:00
}