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