2018-08-30 14:18:55 +02:00
|
|
|
// run-pass
|
2018-09-25 23:51:35 +02:00
|
|
|
#![allow(dead_code)]
|
|
|
|
#![allow(unused_mut)]
|
|
|
|
#![allow(unused_variables)]
|
2015-01-08 02:25:56 +01:00
|
|
|
|
2015-03-17 13:33:26 -07:00
|
|
|
use std::io::{self, Write};
|
2014-01-13 20:34:23 -05:00
|
|
|
|
2013-12-27 00:38:28 -05:00
|
|
|
trait Trait {
|
|
|
|
fn f(&self);
|
|
|
|
}
|
|
|
|
|
2015-03-30 09:38:27 -04:00
|
|
|
#[derive(Copy, Clone)]
|
2013-12-27 00:38:28 -05:00
|
|
|
struct Struct {
|
2015-03-25 17:06:52 -07:00
|
|
|
x: isize,
|
|
|
|
y: isize,
|
2013-12-27 00:38:28 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Trait for Struct {
|
|
|
|
fn f(&self) {
|
2014-01-09 21:06:55 +11:00
|
|
|
println!("Hi!");
|
2013-12-27 00:38:28 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-28 14:47:21 -04:00
|
|
|
fn foo(mut a: Box<dyn Write>) {}
|
2014-01-13 20:34:23 -05:00
|
|
|
|
2013-12-27 00:38:28 -05:00
|
|
|
pub fn main() {
|
|
|
|
let a = Struct { x: 1, y: 2 };
|
2019-05-28 14:47:21 -04:00
|
|
|
let b: Box<dyn Trait> = Box::new(a);
|
2013-12-27 00:38:28 -05:00
|
|
|
b.f();
|
2019-05-28 14:47:21 -04:00
|
|
|
let c: &dyn Trait = &a;
|
2013-12-27 00:38:28 -05:00
|
|
|
c.f();
|
2014-01-13 20:34:23 -05:00
|
|
|
|
2015-03-17 13:33:26 -07:00
|
|
|
let out = io::stdout();
|
2015-02-15 09:52:21 +01:00
|
|
|
foo(Box::new(out));
|
2013-12-27 00:38:28 -05:00
|
|
|
}
|