summaryrefslogtreecommitdiffstats
path: root/tests/ui/closures/2229_closure_analysis/run_pass/destructure_patterns.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
commit218caa410aa38c29984be31a5229b9fa717560ee (patch)
treec54bd55eeb6e4c508940a30e94c0032fbd45d677 /tests/ui/closures/2229_closure_analysis/run_pass/destructure_patterns.rs
parentReleasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz
rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/closures/2229_closure_analysis/run_pass/destructure_patterns.rs')
-rw-r--r--tests/ui/closures/2229_closure_analysis/run_pass/destructure_patterns.rs119
1 files changed, 119 insertions, 0 deletions
diff --git a/tests/ui/closures/2229_closure_analysis/run_pass/destructure_patterns.rs b/tests/ui/closures/2229_closure_analysis/run_pass/destructure_patterns.rs
new file mode 100644
index 000000000..dacc2c616
--- /dev/null
+++ b/tests/ui/closures/2229_closure_analysis/run_pass/destructure_patterns.rs
@@ -0,0 +1,119 @@
+// edition:2021
+// check-pass
+#![warn(unused)]
+
+struct Point {
+ x: u32,
+ y: u32,
+}
+
+fn test1() {
+ let t = (String::from("Hello"), String::from("World"));
+
+ let c = || {
+ let (t1, t2) = t;
+ //~^ WARN unused variable: `t1`
+ //~| WARN unused variable: `t2`
+ };
+
+ c();
+}
+
+fn test2() {
+ let t = (String::from("Hello"), String::from("World"));
+
+ let c = || {
+ let (t1, _) = t;
+ //~^ WARN unused variable: `t1`
+ };
+
+ c();
+}
+
+fn test3() {
+ let t = (String::from("Hello"), String::from("World"));
+
+ let c = || {
+ let (_, t2) = t;
+ //~^ WARN unused variable: `t2`
+ };
+
+ c();
+}
+
+fn test4() {
+ let t = (String::from("Hello"), String::from("World"));
+
+ let c = || {
+ let (_, _) = t;
+ };
+
+ c();
+}
+
+fn test5() {
+ let t = (String::new(), String::new());
+ let _c = || {
+ let _a = match t {
+ (t1, _) => t1,
+ };
+ };
+}
+
+fn test6() {
+ let t = (String::new(), String::new());
+ let _c = || {
+ let _a = match t {
+ (_, t2) => t2,
+ };
+ };
+}
+
+fn test7() {
+ let t = (String::new(), String::new());
+ let _c = || {
+ let _a = match t {
+ (t1, t2) => (t1, t2),
+ };
+ };
+}
+
+fn test8() {
+ let x = 0;
+ let tup = (1, 2);
+ let p = Point { x: 10, y: 20 };
+
+ let c = || {
+ let _ = x;
+ let Point { x, y } = p;
+ //~^ WARN unused variable: `x`
+ println!("{}", y);
+ let (_, _) = tup;
+ };
+
+ c();
+}
+
+fn test9() {
+ let _z = 9;
+ let t = (String::from("Hello"), String::from("World"));
+
+ let c = || {
+ let (_, t) = t;
+ println!("{}", t);
+ };
+
+ c();
+}
+
+fn main() {
+ test1();
+ test2();
+ test3();
+ test4();
+ test5();
+ test6();
+ test7();
+ test8();
+ test9();
+}