@@ -651,20 +651,21 @@ where
651651 use rustc:: mir:: PlaceBase ;
652652
653653 let mut place_ty = match & place. base {
654- PlaceBase :: Local ( mir:: RETURN_PLACE ) => match self . frame ( ) . return_place {
655- Some ( return_place) => {
656- // We use our layout to verify our assumption; caller will validate
657- // their layout on return.
658- PlaceTy {
659- place : * return_place,
660- layout : self . layout_of (
661- self . subst_from_frame_and_normalize_erasing_regions (
662- self . frame ( ) . body . return_ty ( )
663- )
664- ) ?,
665- }
654+ PlaceBase :: Local ( mir:: RETURN_PLACE ) => {
655+ // `return_place` has the *caller* layout, but we want to use our
656+ // `layout to verify our assumption. The caller will validate
657+ // their layout on return.
658+ PlaceTy {
659+ place : match self . frame ( ) . return_place {
660+ Some ( p) => * p,
661+ None => Place :: null ( & * self ) ,
662+ } ,
663+ layout : self . layout_of (
664+ self . subst_from_frame_and_normalize_erasing_regions (
665+ self . frame ( ) . body . return_ty ( )
666+ )
667+ ) ?,
666668 }
667- None => throw_unsup ! ( InvalidNullPointerUsage ) ,
668669 } ,
669670 PlaceBase :: Local ( local) => PlaceTy {
670671 // This works even for dead/uninitialized locals; we check further when writing
@@ -791,8 +792,8 @@ where
791792 // to handle padding properly, which is only correct if we never look at this data with the
792793 // wrong type.
793794
794- let ptr = match self . check_mplace_access ( dest , None )
795- . expect ( "places should be checked on creation" )
795+ // Invalid places are a thing: the return place of a diverging function
796+ let ptr = match self . check_mplace_access ( dest , None ) ?
796797 {
797798 Some ( ptr) => ptr,
798799 None => return Ok ( ( ) ) , // zero-sized access
0 commit comments