@@ -1272,21 +1272,17 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1272
1272
// cases.
1273
1273
let source_info = self . source_info ( scrutinee_span) ;
1274
1274
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.
1284
1283
//
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.
1290
1286
let cause_matched_place = FakeReadCause :: ForMatchedPlace ( None ) ;
1291
1287
1292
1288
if let Some ( scrutinee_place) = scrutinee_place_builder. try_to_place ( self ) {
0 commit comments