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 do not contain managed values, and thus the boxes do
|
2013-08-11 17:58:48 +00:00
|
|
|
// not have headers.
|
|
|
|
|
2013-06-22 07:37:40 +00:00
|
|
|
trait FooTrait {
|
2015-03-26 00:06:52 +00:00
|
|
|
fn foo(&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) -> usize {
|
2013-06-22 07:37:40 +00:00
|
|
|
self.x
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
2019-05-28 18:47:21 +00:00
|
|
|
let foos: Vec<Box<dyn FooTrait>> = vec![
|
2021-08-25 00:39:40 +00:00
|
|
|
Box::new(BarStruct{ x: 0 }) as Box<dyn FooTrait>,
|
|
|
|
Box::new(BarStruct{ x: 1 }) as Box<dyn FooTrait>,
|
|
|
|
Box::new(BarStruct{ x: 2 }) as Box<dyn FooTrait>,
|
2016-10-29 21:54:04 +00:00
|
|
|
];
|
2013-06-22 07:37:40 +00:00
|
|
|
|
2015-03-03 08:42:26 +00:00
|
|
|
for i in 0..foos.len() {
|
2014-10-15 06:05:01 +00:00
|
|
|
assert_eq!(i, foos[i].foo());
|
2013-06-22 07:37:40 +00:00
|
|
|
}
|
|
|
|
}
|