@@ -449,7 +449,32 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
449
449
let layout = this. layout_of ( ty) ?;
450
450
if layout. abi . is_uninhabited ( ) {
451
451
// Return here because we paniced instead of returning normally from the intrinsic.
452
- return this. start_panic ( & format ! ( "Attempted to instantiate uninhabited type {}" , ty) , unwind) ;
452
+ return this. start_panic ( & format ! ( "attempted to instantiate uninhabited type {}" , ty) , unwind) ;
453
+ }
454
+ }
455
+
456
+ "panic_if_zero_invalid" => {
457
+ let ty = substs. type_at ( 0 ) ;
458
+ let layout = this. layout_of ( ty) ?;
459
+ // Check if it permits zeroed raw initialization
460
+ if !layout. might_permit_raw_init ( this, /*zero:*/ true ) . unwrap ( ) {
461
+ // Return here because we paniced instead of returning normally from the intrinsic.
462
+ return this. start_panic ( & format ! ( "attempted to zero-initialize type `{}`, which is invalid" , ty) , unwind) ;
463
+ }
464
+ }
465
+
466
+ "panic_if_any_invalid" => {
467
+ let ty = substs. type_at ( 0 ) ;
468
+ let layout = this. layout_of ( ty) ?;
469
+ // rustc handles all these in a single function, but we don't so we need to make sure `mem::uninitialized::<!>()` returns the right error.
470
+ // So we check for `is_uninhabited` here too.
471
+ if layout. abi . is_uninhabited ( ) {
472
+ return this. start_panic ( & format ! ( "attempted to instantiate uninhabited type {}" , ty) , unwind) ;
473
+ }
474
+ // Check if it permits any raw initialization
475
+ if !layout. might_permit_raw_init ( this, /*zero:*/ false ) . unwrap ( ) {
476
+ // Return here because we paniced instead of returning normally from the intrinsic.
477
+ return this. start_panic ( & format ! ( "attempted to leave type `{}` uninitialized, which is invalid" , ty) , unwind) ;
453
478
}
454
479
}
455
480
0 commit comments