@@ -651,20 +651,21 @@ where
651
651
use rustc:: mir:: PlaceBase ;
652
652
653
653
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
+ ) ?,
666
668
}
667
- None => throw_unsup ! ( InvalidNullPointerUsage ) ,
668
669
} ,
669
670
PlaceBase :: Local ( local) => PlaceTy {
670
671
// This works even for dead/uninitialized locals; we check further when writing
@@ -791,8 +792,8 @@ where
791
792
// to handle padding properly, which is only correct if we never look at this data with the
792
793
// wrong type.
793
794
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 ) ?
796
797
{
797
798
Some ( ptr) => ptr,
798
799
None => return Ok ( ( ) ) , // zero-sized access
0 commit comments