Closed as not planned
Description
I tried this code:
union U {
a: i32,
b: (),
}
fn main() {
let u = U {a: 123};
match u {
U {b: ()} => println!("Hello, world!"),
}
}
I expected to see this happen: Compiler error, since pattern matching on a union is done without using unsafe
; see the reference.
Instead, this happened: Compile succeeds.
It seems that this only works when matching with a zero-sized union field, and it does not appear possible to actually extract the field's value by binding it to a name.
Meta
rustc --version --verbose
:
rustc 1.68.2 (9eb3afe9e 2023-03-27)
binary: rustc
commit-hash: 9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0
commit-date: 2023-03-27
host: x86_64-apple-darwin
release: 1.68.2
LLVM version: 15.0.6