diff --git a/gcc/testsuite/rust/compile/issue-2906.rs b/gcc/testsuite/rust/compile/issue-2906.rs new file mode 100644 index 000000000000..20abcb095b8f --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-2906.rs @@ -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 index 000000000000..d3ca8ae1c5d4 --- /dev/null +++ b/gcc/testsuite/rust/execute/torture/issue-2906.rs @@ -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 +}