diff options
author | Raiki Tamura <tamaron1203@gmail.com> | 2024-07-31 16:09:30 +0900 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2025-03-19 15:32:04 +0100 |
commit | b7e79e38fe97e9f41008f0a48bd41ffdd7a2895c (patch) | |
tree | 84fd5b4f5259ebfc8e33cb8d8ef3818d5a1eef4d /gcc/testsuite/rust | |
parent | 85a3c48f51dbef4e74f806aca36825a6164db636 (diff) | |
download | gcc-b7e79e38fe97e9f41008f0a48bd41ffdd7a2895c.zip gcc-b7e79e38fe97e9f41008f0a48bd41ffdd7a2895c.tar.gz gcc-b7e79e38fe97e9f41008f0a48bd41ffdd7a2895c.tar.bz2 |
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 <tamaron1203@gmail.com>
Diffstat (limited to 'gcc/testsuite/rust')
-rw-r--r-- | gcc/testsuite/rust/compile/match8.rs | 19 |
1 files changed, 19 insertions, 0 deletions
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() {} |