]> git.proxmox.com Git - rustc.git/blame - src/test/ui/closures/2229_closure_analysis/run_pass/destructure_patterns.rs
New upstream version 1.55.0+dfsg1
[rustc.git] / src / test / ui / closures / 2229_closure_analysis / run_pass / destructure_patterns.rs
CommitLineData
136023e0
XL
1// edition:2021
2// check-pass
6a06907d
XL
3#![warn(unused)]
4
5struct Point {
6 x: u32,
7 y: u32,
8}
9
10fn test1() {
11 let t = (String::from("Hello"), String::from("World"));
12
13 let c = || {
14 let (t1, t2) = t;
15 //~^ WARN unused variable: `t1`
16 //~| WARN unused variable: `t2`
17 };
18
19 c();
20}
21
22fn test2() {
23 let t = (String::from("Hello"), String::from("World"));
24
25 let c = || {
26 let (t1, _) = t;
27 //~^ WARN unused variable: `t1`
28 };
29
30 c();
31}
32
33fn test3() {
34 let t = (String::from("Hello"), String::from("World"));
35
36 let c = || {
37 let (_, t2) = t;
38 //~^ WARN unused variable: `t2`
39 };
40
41 c();
42}
43
44fn test4() {
45 let t = (String::from("Hello"), String::from("World"));
46 //~^ WARN unused variable: `t`
47
48 let c = || {
49 let (_, _) = t;
50 };
51
52 c();
53}
54
55fn test5() {
56 let t = (String::new(), String::new());
57 let _c = || {
58 let _a = match t {
59 (t1, _) => t1,
60 };
61 };
62}
63
64fn test6() {
65 let t = (String::new(), String::new());
66 let _c = || {
67 let _a = match t {
68 (_, t2) => t2,
69 };
70 };
71}
72
73fn test7() {
74 let t = (String::new(), String::new());
75 let _c = || {
76 let _a = match t {
77 (t1, t2) => (t1, t2),
78 };
79 };
80}
81
82fn test8() {
83 let x = 0;
84 //~^ WARN unused variable: `x`
85 let tup = (1, 2);
86 //~^ WARN unused variable: `tup`
87 let p = Point { x: 10, y: 20 };
88
89 let c = || {
90 let _ = x;
91 let Point { x, y } = p;
92 //~^ WARN unused variable: `x`
93 println!("{}", y);
94 let (_, _) = tup;
95 };
96
97 c();
98}
99
100fn test9() {
101 let _z = 9;
102 let t = (String::from("Hello"), String::from("World"));
103
104 let c = || {
105 let (_, t) = t;
106 println!("{}", t);
107 };
108
109 c();
110}
111
112fn main() {
113 test1();
114 test2();
115 test3();
116 test4();
117 test5();
118 test6();
119 test7();
120 test8();
121 test9();
122}