2019-07-26 21:54:25 +00:00
|
|
|
// run-pass
|
2013-08-11 17:58:48 +00:00
|
|
|
// Test invoked `&self` methods on owned objects where the values
|
2014-05-06 01:56:44 +00:00
|
|
|
// closed over contain managed values. This implies that the boxes
|
2013-08-11 17:58:48 +00:00
|
|
|
// will have headers that must be skipped over.
|
|
|
|
|
2013-06-22 07:37:40 +00:00
|
|
|
trait FooTrait {
|
2015-03-26 00:06:52 +00:00
|
|
|
fn foo(self: Box<Self>) -> usize;
|
2013-06-22 07:37:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct BarStruct {
|
2015-03-26 00:06:52 +00:00
|
|
|
x: usize
|
2013-06-22 07:37:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl FooTrait for BarStruct {
|
2015-03-26 00:06:52 +00:00
|
|
|
fn foo(self: Box<BarStruct>) -> usize {
|
2013-06-22 07:37:40 +00:00
|
|
|
self.x
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
2021-08-25 00:39:40 +00:00
|
|
|
let foo = Box::new(BarStruct{ x: 22 }) as Box<dyn FooTrait>;
|
2013-08-11 17:58:48 +00:00
|
|
|
assert_eq!(22, foo.foo());
|
2013-06-22 07:37:40 +00:00
|
|
|
}
|