diff options
| author | bors <bors@rust-lang.org> | 2024-04-04 05:10:51 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-04-04 05:10:51 +0000 |
| commit | 394aa87a74a3d37c5643dae13acde583482f0359 (patch) | |
| tree | 0df96b7dd21d20796e58c38a8f7f36413be4a6d8 /compiler/rustc_pattern_analysis/src/constructor.rs | |
| parent | 92509847a7fe4d829c5fb73eef1b839d6b9fdbd8 (diff) | |
| parent | 9c334143d84733cbd26f1698dd9137c09f34a77b (diff) | |
| download | rust-394aa87a74a3d37c5643dae13acde583482f0359.tar.gz rust-394aa87a74a3d37c5643dae13acde583482f0359.zip | |
Auto merge of #3447 - rust-lang:rustup-2024-04-04, r=saethlin
Automatic Rustup
Diffstat (limited to 'compiler/rustc_pattern_analysis/src/constructor.rs')
| -rw-r--r-- | compiler/rustc_pattern_analysis/src/constructor.rs | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/compiler/rustc_pattern_analysis/src/constructor.rs b/compiler/rustc_pattern_analysis/src/constructor.rs index 1c9a9ab0f72..44f09b66bf6 100644 --- a/compiler/rustc_pattern_analysis/src/constructor.rs +++ b/compiler/rustc_pattern_analysis/src/constructor.rs @@ -140,6 +140,34 @@ //! [`ConstructorSet::split`]. The invariants of [`SplitConstructorSet`] are also of interest. //! //! +//! ## Unions +//! +//! Unions allow us to match a value via several overlapping representations at the same time. For +//! example, the following is exhaustive because when seeing the value as a boolean we handled all +//! possible cases (other cases such as `n == 3` would trigger UB). +//! +//! ```rust +//! # fn main() { +//! union U8AsBool { +//! n: u8, +//! b: bool, +//! } +//! let x = U8AsBool { n: 1 }; +//! unsafe { +//! match x { +//! U8AsBool { n: 2 } => {} +//! U8AsBool { b: true } => {} +//! U8AsBool { b: false } => {} +//! } +//! } +//! # } +//! ``` +//! +//! Pattern-matching has no knowledge that e.g. `false as u8 == 0`, so the values we consider in the +//! algorithm look like `U8AsBool { b: true, n: 2 }`. In other words, for the most part a union is +//! treated like a struct with the same fields. The difference lies in how we construct witnesses of +//! non-exhaustiveness. +//! //! //! ## Opaque patterns //! @@ -974,7 +1002,6 @@ impl<Cx: PatCx> ConstructorSet<Cx> { /// any) are missing; 2/ split constructors to handle non-trivial intersections e.g. on ranges /// or slices. This can get subtle; see [`SplitConstructorSet`] for details of this operation /// and its invariants. - #[instrument(level = "debug", skip(self, ctors), ret)] pub fn split<'a>( &self, ctors: impl Iterator<Item = &'a Constructor<Cx>> + Clone, |
