2013-08-11 19:58:48 +02:00
|
|
|
// Test invoked `&self` methods on owned objects where the values
|
2014-05-06 03:56:44 +02:00
|
|
|
// closed over do not contain managed values, and thus the boxes do
|
2013-08-11 19:58:48 +02:00
|
|
|
// not have headers.
|
|
|
|
|
2015-01-08 02:25:56 +01:00
|
|
|
#![feature(box_syntax)]
|
|
|
|
|
2014-03-06 00:28:08 +01:00
|
|
|
|
2013-06-22 09:37:40 +02:00
|
|
|
trait FooTrait {
|
2015-03-26 01:06:52 +01:00
|
|
|
fn foo(&self) -> usize;
|
2013-06-22 09:37:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
struct BarStruct {
|
2015-03-26 01:06:52 +01:00
|
|
|
x: usize
|
2013-06-22 09:37:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl FooTrait for BarStruct {
|
2015-03-26 01:06:52 +01:00
|
|
|
fn foo(&self) -> usize {
|
2013-06-22 09:37:40 +02:00
|
|
|
self.x
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
2016-10-29 23:54:04 +02:00
|
|
|
let foos: Vec<Box<FooTrait>> = vec![
|
2014-05-06 03:56:44 +02:00
|
|
|
box BarStruct{ x: 0 } as Box<FooTrait>,
|
|
|
|
box BarStruct{ x: 1 } as Box<FooTrait>,
|
|
|
|
box BarStruct{ x: 2 } as Box<FooTrait>
|
2016-10-29 23:54:04 +02:00
|
|
|
];
|
2013-06-22 09:37:40 +02:00
|
|
|
|
2015-03-03 09:42:26 +01:00
|
|
|
for i in 0..foos.len() {
|
2014-10-15 08:05:01 +02:00
|
|
|
assert_eq!(i, foos[i].foo());
|
2013-06-22 09:37:40 +02:00
|
|
|
}
|
|
|
|
}
|