]> git.lizzy.rs Git - rust.git/blob - src/test/ui/traits/objects-owned-object-borrowed-method-headerless.rs
:arrow_up: rust-analyzer
[rust.git] / src / test / ui / traits / objects-owned-object-borrowed-method-headerless.rs
1 // run-pass
2 // Test invoked `&self` methods on owned objects where the values
3 // closed over do not contain managed values, and thus the boxes do
4 // not have headers.
5
6 trait FooTrait {
7     fn foo(&self) -> usize;
8 }
9
10 struct BarStruct {
11     x: usize
12 }
13
14 impl FooTrait for BarStruct {
15     fn foo(&self) -> usize {
16         self.x
17     }
18 }
19
20 pub fn main() {
21     let foos: Vec<Box<dyn FooTrait>> = vec![
22         Box::new(BarStruct{ x: 0 }) as Box<dyn FooTrait>,
23         Box::new(BarStruct{ x: 1 }) as Box<dyn FooTrait>,
24         Box::new(BarStruct{ x: 2 }) as Box<dyn FooTrait>,
25     ];
26
27     for i in 0..foos.len() {
28         assert_eq!(i, foos[i].foo());
29     }
30 }