Skip to content

Commit

Permalink
Add testcases for handling struct as scrutinee for match expr
Browse files Browse the repository at this point in the history
gcc/testsuite/ChangeLog:

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

Signed-off-by: Nobel Singh <[email protected]>
  • Loading branch information
nobel-sh authored and P-E-P committed May 15, 2024
1 parent 9e45b86 commit 154ce77
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
10 changes: 10 additions & 0 deletions gcc/testsuite/rust/compile/issue-2906.rs
Original file line number Diff line number Diff line change
@@ -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 => { }
}
}
34 changes: 34 additions & 0 deletions gcc/testsuite/rust/execute/torture/issue-2906.rs
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 154ce77

Please sign in to comment.