diff options
| author | Nadrieril <nadrieril+git@gmail.com> | 2024-06-22 18:21:03 +0200 |
|---|---|---|
| committer | Nadrieril <nadrieril+git@gmail.com> | 2024-06-22 19:06:40 +0200 |
| commit | beb1d35d7d63d331089620c60d591bab7e6495a5 (patch) | |
| tree | 24140111a43e708d67710a2f2abb80e23f189446 | |
| parent | ff49c3769b0ec5b1abc628e55c7547e765086e6a (diff) | |
| download | rust-beb1d35d7d63d331089620c60d591bab7e6495a5.tar.gz rust-beb1d35d7d63d331089620c60d591bab7e6495a5.zip | |
Change comment to reflect switch to THIR unsafeck
| -rw-r--r-- | compiler/rustc_mir_build/src/build/matches/mod.rs | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/compiler/rustc_mir_build/src/build/matches/mod.rs b/compiler/rustc_mir_build/src/build/matches/mod.rs index f9333a165ce..a92272c9809 100644 --- a/compiler/rustc_mir_build/src/build/matches/mod.rs +++ b/compiler/rustc_mir_build/src/build/matches/mod.rs @@ -1258,21 +1258,17 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // cases. let source_info = self.source_info(scrutinee_span); - // Matching on a `scrutinee_place` with an uninhabited type doesn't - // generate any memory reads by itself, and so if the place "expression" - // contains unsafe operations like raw pointer dereferences or union - // field projections, we wouldn't know to require an `unsafe` block - // around a `match` equivalent to `std::intrinsics::unreachable()`. - // See issue #47412 for this hole being discovered in the wild. - // - // HACK(eddyb) Work around the above issue by adding a dummy inspection - // of `scrutinee_place`, specifically by applying `ReadForMatch`. + // Matching on a scrutinee place of an uninhabited type doesn't generate any memory + // reads by itself, and so if the place is uninitialized we wouldn't know. In order to + // disallow the following: + // ```rust + // let x: !; + // match x {} + // ``` + // we add a dummy read on the place. // - // NOTE: ReadForMatch also checks that the scrutinee is initialized. - // This is currently needed to not allow matching on an uninitialized, - // uninhabited value. If we get never patterns, those will check that - // the place is initialized, and so this read would only be used to - // check safety. + // NOTE: If we require never patterns for empty matches, those will check that the place + // is initialized, and so this read would no longer be needed. let cause_matched_place = FakeReadCause::ForMatchedPlace(None); if let Some(scrutinee_place) = scrutinee_place_builder.try_to_place(self) { |
