]> git.lizzy.rs Git - rust.git/blob - src/test/ui/objects-owned-object-borrowed-method-headerless.rs
Auto merge of #87150 - rusticstuff:simplify_wrapping_neg, r=m-ou-se
[rust.git] / src / test / ui / 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 #![feature(box_syntax)]
7
8
9 trait FooTrait {
10     fn foo(&self) -> usize;
11 }
12
13 struct BarStruct {
14     x: usize
15 }
16
17 impl FooTrait for BarStruct {
18     fn foo(&self) -> usize {
19         self.x
20     }
21 }
22
23 pub fn main() {
24     let foos: Vec<Box<dyn FooTrait>> = vec![
25         box BarStruct{ x: 0 } as Box<dyn FooTrait>,
26         box BarStruct{ x: 1 } as Box<dyn FooTrait>,
27         box BarStruct{ x: 2 } as Box<dyn FooTrait>
28     ];
29
30     for i in 0..foos.len() {
31         assert_eq!(i, foos[i].foo());
32     }
33 }