]>
git.proxmox.com Git - rustc.git/blob - src/test/ui/closures/2229_closure_analysis/move_closure.rs
1 // Test that move closures drop derefs with `capture_disjoint_fields` enabled.
3 #![feature(capture_disjoint_fields)]
4 //~^ WARNING: the feature `capture_disjoint_fields` is incomplete
5 //~| NOTE: `#[warn(incomplete_features)]` on by default
6 //~| NOTE: see issue #53488 <https://github.com/rust-lang/rust/issues/53488>
7 #![feature(rustc_attrs)]
9 fn simple_move_closure() {
13 let t
= T(S("s".into()));
14 let mut c
= #[rustc_capture_analysis]
15 //~^ ERROR: attributes on expressions are experimental
16 //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
18 //~^ ERROR: First Pass analysis includes:
19 //~| ERROR: Min Capture analysis includes:
20 t
.0.0 = "new S".into();
21 //~^ NOTE: Capturing t[(0, 0),(0, 0)] -> ByValue
22 //~| NOTE: Min Capture t[(0, 0),(0, 0)] -> ByValue
27 // Test move closure use reborrows when using references
32 let mut c
= #[rustc_capture_analysis]
33 //~^ ERROR: attributes on expressions are experimental
34 //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
36 //~^ ERROR: First Pass analysis includes:
37 //~| ERROR: Min Capture analysis includes:
39 //~^ NOTE: Capturing ref_s[Deref] -> UniqueImmBorrow
40 //~| NOTE: Min Capture ref_s[Deref] -> UniqueImmBorrow
45 // Test move closure use reborrows when using references
46 fn struct_contains_ref_to_another_struct_1() {
48 struct T
<'a
>(&'a
mut S
);
50 let mut s
= S("s".into());
53 let mut c
= #[rustc_capture_analysis]
54 //~^ ERROR: attributes on expressions are experimental
55 //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
57 //~^ ERROR: First Pass analysis includes:
58 //~| ERROR: Min Capture analysis includes:
59 t
.0.0 = "new s".into();
60 //~^ NOTE: Capturing t[(0, 0),Deref,(0, 0)] -> UniqueImmBorrow
61 //~| NOTE: Min Capture t[(0, 0),Deref,(0, 0)] -> UniqueImmBorrow
67 // Test that we can use reborrows to read data of Copy types
68 // i.e. without truncating derefs
69 fn struct_contains_ref_to_another_struct_2() {
76 let mut c
= #[rustc_capture_analysis]
77 //~^ ERROR: attributes on expressions are experimental
78 //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
80 //~^ ERROR: First Pass analysis includes:
81 //~| ERROR: Min Capture analysis includes:
83 //~^ NOTE: Capturing t[(0, 0),Deref,(0, 0)] -> ImmBorrow
84 //~| NOTE: Min Capture t[(0, 0),Deref,(0, 0)] -> ImmBorrow
90 // Test that we can use truncate to move out of !Copy types
91 fn struct_contains_ref_to_another_struct_3() {
95 let s
= S("s".into());
98 let mut c
= #[rustc_capture_analysis]
99 //~^ ERROR: attributes on expressions are experimental
100 //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
102 //~^ ERROR: First Pass analysis includes:
103 //~| ERROR: Min Capture analysis includes:
105 //~^ NOTE: Capturing t[(0, 0),Deref,(0, 0)] -> ImmBorrow
106 //~| NOTE: Capturing t[(0, 0)] -> ByValue
107 //~| NOTE: Min Capture t[(0, 0)] -> ByValue
113 // Test that derefs of box are truncated in move closures
114 fn truncate_box_derefs() {
117 let b
= Box
::new(S(10));
119 let c
= #[rustc_capture_analysis]
120 //~^ ERROR: attributes on expressions are experimental
121 //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
123 //~^ ERROR: First Pass analysis includes:
124 //~| ERROR: Min Capture analysis includes:
126 //~^ NOTE: Capturing b[Deref,(0, 0)] -> ByValue
127 //~| NOTE: Capturing b[] -> ByValue
128 //~| NOTE: Min Capture b[] -> ByValue
135 simple_move_closure();
137 struct_contains_ref_to_another_struct_1();
138 struct_contains_ref_to_another_struct_2();
139 struct_contains_ref_to_another_struct_3();
140 truncate_box_derefs();