@@ -1272,21 +1272,17 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
12721272 // cases.
12731273 let source_info = self . source_info ( scrutinee_span) ;
12741274
1275- // Matching on a `scrutinee_place` with an uninhabited type doesn't
1276- // generate any memory reads by itself, and so if the place "expression"
1277- // contains unsafe operations like raw pointer dereferences or union
1278- // field projections, we wouldn't know to require an `unsafe` block
1279- // around a `match` equivalent to `std::intrinsics::unreachable()`.
1280- // See issue #47412 for this hole being discovered in the wild.
1281- //
1282- // HACK(eddyb) Work around the above issue by adding a dummy inspection
1283- // of `scrutinee_place`, specifically by applying `ReadForMatch`.
1275+ // Matching on a scrutinee place of an uninhabited type doesn't generate any memory
1276+ // reads by itself, and so if the place is uninitialized we wouldn't know. In order to
1277+ // disallow the following:
1278+ // ```rust
1279+ // let x: !;
1280+ // match x {}
1281+ // ```
1282+ // we add a dummy read on the place.
12841283 //
1285- // NOTE: ReadForMatch also checks that the scrutinee is initialized.
1286- // This is currently needed to not allow matching on an uninitialized,
1287- // uninhabited value. If we get never patterns, those will check that
1288- // the place is initialized, and so this read would only be used to
1289- // check safety.
1284+ // NOTE: If we require never patterns for empty matches, those will check that the place
1285+ // is initialized, and so this read would no longer be needed.
12901286 let cause_matched_place = FakeReadCause :: ForMatchedPlace ( None ) ;
12911287
12921288 if let Some ( scrutinee_place) = scrutinee_place_builder. try_to_place ( self ) {
0 commit comments