2018-08-30 14:18:55 +02:00
|
|
|
// run-pass
|
2014-05-05 18:56:44 -07:00
|
|
|
|
2012-11-29 10:59:49 -08:00
|
|
|
trait Foo {
|
2014-07-07 23:19:35 -07:00
|
|
|
fn f(self: Box<Self>);
|
2012-11-29 10:59:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
struct S {
|
2015-03-25 17:06:52 -07:00
|
|
|
x: isize
|
2012-11-29 10:59:49 -08:00
|
|
|
}
|
|
|
|
|
2013-02-14 11:47:00 -08:00
|
|
|
impl Foo for S {
|
2014-07-07 23:19:35 -07:00
|
|
|
fn f(self: Box<S>) {
|
2013-05-18 22:02:45 -04:00
|
|
|
assert_eq!(self.x, 3);
|
2012-11-29 10:59:49 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-01 19:43:17 -08:00
|
|
|
pub fn main() {
|
2021-08-25 02:39:40 +02:00
|
|
|
let x = Box::new(S { x: 3 });
|
2019-05-28 14:46:13 -04:00
|
|
|
let y = x as Box<dyn Foo>;
|
2012-11-29 10:59:49 -08:00
|
|
|
y.f();
|
|
|
|
}
|