From b7e79e38fe97e9f41008f0a48bd41ffdd7a2895c Mon Sep 17 00:00:00 2001 From: Raiki Tamura Date: Wed, 31 Jul 2024 16:09:30 +0900 Subject: rust: Add checking for union patterns gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): Add check for union patterns. gcc/testsuite/ChangeLog: * rust/compile/match8.rs: New test. Signed-off-by: Raiki Tamura --- gcc/testsuite/rust/compile/match8.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 gcc/testsuite/rust/compile/match8.rs (limited to 'gcc/testsuite/rust/compile') diff --git a/gcc/testsuite/rust/compile/match8.rs b/gcc/testsuite/rust/compile/match8.rs new file mode 100644 index 0000000..336b313 --- /dev/null +++ b/gcc/testsuite/rust/compile/match8.rs @@ -0,0 +1,19 @@ +union MyUnion { + f1: u32, + f2: f32, +} + +fn f(u: MyUnion) -> i32 { + unsafe { + match u { + MyUnion { f1: 10 } => 0, + MyUnion { f2 } => 0, + MyUnion { f1: 10, f2: 10.0 } => 0, // { dg-error "union patterns should have exactly one field" "" } + MyUnion {} => 0, // { dg-error "union patterns should have exactly one field" "" } + MyUnion { f1: () } => 0, // { dg-error "expected u32, found tuple" "" } + _ => 1, + } + } +} + +fn main() {} -- cgit v1.1