Fix the tagged-union pattern-matching recommendation The union chapter recommends matching a tag and its corresponding union field together in a single pattern when implementing a C-style tagged union. This suggests the idiom is safe. But it's not. We don't guarantee the order that subpatterns are checked -- this could only be safe if we could be sure the tag is checked first. And, in fact, if an or-pattern is used when matching the tag, then `rustc` defers the check, causing actual UB (see rust-lang/rust#158387). Let's fix that. We can remove the `items.union.pattern.subpattern` rule entirely -- it's trivially true that a pattern can appear as a subpattern. In its place, let's add a warning admonition that highlights what isn't guaranteed and describes what people should do instead.
This document is the primary reference for the Rust programming language.
See the Reference Developer Guide for information on contributing to the Reference.