]> git.lizzy.rs Git - rust.git/blob - tests/ui/closures/2229_closure_analysis/wild_patterns.rs
Rollup merge of #107190 - fmease:fix-81698, r=compiler-errors
[rust.git] / tests / ui / closures / 2229_closure_analysis / wild_patterns.rs
1 // edition:2021
2
3 #![feature(rustc_attrs)]
4
5 // Test to ensure that we can handle cases where
6 // let statements create no bindings are initialized
7 // using a Place expression
8 //
9 // Note: Currently when feature `capture_disjoint_fields` is enabled
10 // we can't handle such cases. So the test current use `_x` instead of
11 // `_` until the issue is resolved.
12 // Check rust-lang/project-rfc-2229#24 for status.
13
14 struct Point {
15     x: i32,
16     y: i32,
17 }
18
19 fn wild_struct() {
20     let p = Point { x: 10, y: 20 };
21
22     let c = #[rustc_capture_analysis]
23     //~^ ERROR: attributes on expressions are experimental
24     //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
25     || {
26     //~^ ERROR: First Pass analysis includes:
27     //~| ERROR: Min Capture analysis includes:
28         // FIXME(arora-aman): Change `_x` to `_`
29         let Point { x: _x, y: _ } = p;
30         //~^ NOTE: Capturing p[(0, 0)] -> ImmBorrow
31         //~| NOTE: Min Capture p[(0, 0)] -> ImmBorrow
32     };
33
34     c();
35 }
36
37 fn wild_tuple() {
38     let t = (String::new(), 10);
39
40     let c = #[rustc_capture_analysis]
41     //~^ ERROR: attributes on expressions are experimental
42     //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
43     || {
44     //~^ ERROR: First Pass analysis includes:
45     //~| ERROR: Min Capture analysis includes:
46         // FIXME(arora-aman): Change `_x` to `_`
47         let (_x, _) = t;
48         //~^ NOTE: Capturing t[(0, 0)] -> ByValue
49         //~| NOTE: Min Capture t[(0, 0)] -> ByValue
50     };
51
52     c();
53 }
54
55 fn wild_arr() {
56     let arr = [String::new(), String::new()];
57
58     let c = #[rustc_capture_analysis]
59     //~^ ERROR: attributes on expressions are experimental
60     //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
61     || {
62     //~^ ERROR: First Pass analysis includes:
63     //~| ERROR: Min Capture analysis includes:
64         // FIXME(arora-aman): Change `_x` to `_`
65         let [_x, _] = arr;
66         //~^ NOTE: Capturing arr[Index] -> ByValue
67         //~| NOTE: Min Capture arr[] -> ByValue
68     };
69
70     c();
71 }
72
73 fn main() {}