]> git.lizzy.rs Git - rust.git/blob - tests/ui/closures/2229_closure_analysis/by_value.rs
Rollup merge of #107248 - erikdesjardins:addrspace, r=oli-obk
[rust.git] / tests / ui / closures / 2229_closure_analysis / by_value.rs
1 // edition:2021
2
3 // Test that we handle derferences properly when only some of the captures are being moved with
4 // `capture_disjoint_fields` enabled.
5 #![feature(rustc_attrs)]
6
7 #[derive(Debug, Default)]
8 struct SomeLargeType;
9 struct MuchLargerType([SomeLargeType; 32]);
10
11 // Ensure that we don't capture any derefs when moving captures into the closures,
12 // i.e. only data from the enclosing stack is moved.
13 fn big_box() {
14     let s = MuchLargerType(Default::default());
15     let b = Box::new(s);
16     let t = (b, 10);
17
18     let c = #[rustc_capture_analysis]
19     //~^ ERROR: attributes on expressions are experimental
20     //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
21     || {
22     //~^ First Pass analysis includes:
23     //~| Min Capture analysis includes:
24         let p = t.0.0;
25         //~^ NOTE: Capturing t[(0, 0),Deref,(0, 0)] -> ByValue
26         //~| NOTE: Min Capture t[(0, 0)] -> ByValue
27         println!("{} {:?}", t.1, p);
28         //~^ NOTE: Capturing t[(1, 0)] -> ImmBorrow
29         //~| NOTE: Min Capture t[(1, 0)] -> ImmBorrow
30     };
31
32     c();
33 }
34
35 fn main() {
36     big_box();
37 }