2018-08-30 12:18:55 +00:00
|
|
|
// run-pass
|
2018-09-25 21:51:35 +00:00
|
|
|
#![allow(dead_code)]
|
|
|
|
#![allow(unused_mut)]
|
|
|
|
#![allow(unused_variables)]
|
2015-01-08 01:25:56 +00:00
|
|
|
|
2015-03-17 20:33:26 +00:00
|
|
|
use std::io::{self, Write};
|
2014-01-14 01:34:23 +00:00
|
|
|
|
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 {
|
2015-03-26 00:06:52 +00:00
|
|
|
x: isize,
|
|
|
|
y: isize,
|
2013-12-27 05:38:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Trait for Struct {
|
|
|
|
fn f(&self) {
|
2014-01-09 10:06:55 +00:00
|
|
|
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>) {}
|
2014-01-14 01:34:23 +00:00
|
|
|
|
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();
|
2014-01-14 01:34:23 +00:00
|
|
|
|
2015-03-17 20:33:26 +00:00
|
|
|
let out = io::stdout();
|
2015-02-15 08:52:21 +00:00
|
|
|
foo(Box::new(out));
|
2013-12-27 05:38:28 +00:00
|
|
|
}
|