@@ -444,35 +444,20 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
444
444
this. write_scalar ( result_ptr, dest) ?;
445
445
}
446
446
447
- "panic_if_uninhabited" => {
447
+ "panic_if_uninhabited" |
448
+ "panic_if_zero_invalid" |
449
+ "panic_if_any_invalid" => {
448
450
let ty = substs. type_at ( 0 ) ;
449
451
let layout = this. layout_of ( ty) ?;
450
452
if layout. abi . is_uninhabited ( ) {
451
453
// 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) ;
454
+ return this. start_panic ( & format ! ( "attempted to instantiate uninhabited type `{}` " , ty) , unwind) ;
453
455
}
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 ( ) {
456
+ if intrinsic_name == "panic_if_zero_invalid" && !layout. might_permit_raw_init ( this, /*zero:*/ true ) . unwrap ( ) {
461
457
// Return here because we paniced instead of returning normally from the intrinsic.
462
458
return this. start_panic ( & format ! ( "attempted to zero-initialize type `{}`, which is invalid" , ty) , unwind) ;
463
459
}
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 ( ) {
460
+ if intrinsic_name == "panic_if_any_invalid" && !layout. might_permit_raw_init ( this, /*zero:*/ false ) . unwrap ( ) {
476
461
// Return here because we paniced instead of returning normally from the intrinsic.
477
462
return this. start_panic ( & format ! ( "attempted to leave type `{}` uninitialized, which is invalid" , ty) , unwind) ;
478
463
}
0 commit comments