-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add testcases for handling struct as scrutinee for match expr
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
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 => { } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |