]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Add testcases for handling struct as scrutinee for match expr
authorNobel Singh <nobel2073@gmail.com>
Tue, 23 Apr 2024 20:22:52 +0000 (02:07 +0545)
committerArthur Cohen <arthur.cohen@embecosm.com>
Mon, 17 Mar 2025 15:35:23 +0000 (16:35 +0100)
gcc/testsuite/ChangeLog:

* rust/compile/issue-2906.rs: New test.
* rust/execute/torture/issue-2906.rs: New test.

Signed-off-by: Nobel Singh <nobel2073@gmail.com>
gcc/testsuite/rust/compile/issue-2906.rs [new file with mode: 0644]
gcc/testsuite/rust/execute/torture/issue-2906.rs [new file with mode: 0644]

diff --git a/gcc/testsuite/rust/compile/issue-2906.rs b/gcc/testsuite/rust/compile/issue-2906.rs
new file mode 100644 (file)
index 0000000..20abcb0
--- /dev/null
@@ -0,0 +1,10 @@
+// { dg-warning "field is never read: .a." "" { target *-*-* } .-1 }
+struct Foo { a: i32 }
+
+fn main() {
+    let a = Foo { a: 15 };
+    
+    match a {
+        b => { }
+    }
+}
\ No newline at end of file
diff --git a/gcc/testsuite/rust/execute/torture/issue-2906.rs b/gcc/testsuite/rust/execute/torture/issue-2906.rs
new file mode 100644 (file)
index 0000000..d3ca8ae
--- /dev/null
@@ -0,0 +1,34 @@
+// { dg-warning "field is never read: .x." "" { target *-*-* } .-1 }
+// { dg-warning "field is never read: .y." "" { target *-*-* } .-2 }
+struct Point {
+    x: u32,
+    y: u32,
+}
+
+fn is_origin(p: Point) -> bool {
+    match p {
+        Point { x, y } => {
+            if x == 0 && y == 0 {
+                return true;
+            }
+            false
+        }
+        _ => false,
+    }
+}
+
+fn main() -> i32 {
+    let p = Point { x: 0, y: 0 };
+    let q = Point { x: 0, y: 1 };
+    let mut retval = 2;
+    
+    if is_origin(p) {
+        retval -= 1;
+    }
+    
+    if !is_origin(q) {
+        retval -= 1;
+    }
+
+    retval
+}