@@ -22,7 +22,7 @@ pub(crate) use cpuid::codegen_cpuid_call;
22
22
pub ( crate ) use llvm:: codegen_llvm_intrinsic_call;
23
23
24
24
use rustc_middle:: ty:: layout:: HasParamEnv ;
25
- use rustc_middle:: ty:: print:: with_no_trimmed_paths;
25
+ use rustc_middle:: ty:: print:: { with_no_trimmed_paths, with_no_visible_paths } ;
26
26
use rustc_middle:: ty:: subst:: SubstsRef ;
27
27
use rustc_span:: symbol:: { kw, sym, Symbol } ;
28
28
@@ -640,47 +640,33 @@ fn codegen_regular_intrinsic_call<'tcx>(
640
640
sym:: assert_inhabited | sym:: assert_zero_valid | sym:: assert_mem_uninitialized_valid => {
641
641
intrinsic_args ! ( fx, args => ( ) ; intrinsic) ;
642
642
643
- let layout = fx. layout_of ( substs. type_at ( 0 ) ) ;
644
- if layout. abi . is_uninhabited ( ) {
645
- with_no_trimmed_paths ! ( {
646
- crate :: base:: codegen_panic_nounwind(
647
- fx,
648
- & format!( "attempted to instantiate uninhabited type `{}`" , layout. ty) ,
649
- source_info,
650
- )
651
- } ) ;
652
- return ;
653
- }
654
-
655
- if intrinsic == sym:: assert_zero_valid
656
- && !fx. tcx . permits_zero_init ( fx. param_env ( ) . and ( layout) )
657
- {
658
- with_no_trimmed_paths ! ( {
659
- crate :: base:: codegen_panic_nounwind(
660
- fx,
661
- & format!(
662
- "attempted to zero-initialize type `{}`, which is invalid" ,
663
- layout. ty
664
- ) ,
665
- source_info,
666
- ) ;
667
- } ) ;
668
- return ;
669
- }
670
-
671
- if intrinsic == sym:: assert_mem_uninitialized_valid
672
- && !fx. tcx . permits_uninit_init ( fx. param_env ( ) . and ( layout) )
673
- {
674
- with_no_trimmed_paths ! ( {
675
- crate :: base:: codegen_panic_nounwind(
676
- fx,
677
- & format!(
678
- "attempted to leave type `{}` uninitialized, which is invalid" ,
679
- layout. ty
680
- ) ,
681
- source_info,
682
- )
643
+ let ty = substs. type_at ( 0 ) ;
644
+ let layout = fx. layout_of ( ty) ;
645
+ let do_panic = match intrinsic {
646
+ sym:: assert_inhabited => layout. abi . is_uninhabited ( ) ,
647
+ sym:: assert_zero_valid => !fx. tcx . permits_zero_init ( fx. param_env ( ) . and ( layout) ) ,
648
+ sym:: assert_mem_uninitialized_valid => {
649
+ !fx. tcx . permits_uninit_init ( fx. param_env ( ) . and ( layout) )
650
+ }
651
+ _ => unreachable ! ( ) ,
652
+ } ;
653
+ if do_panic {
654
+ let msg_str = with_no_visible_paths ! ( {
655
+ with_no_trimmed_paths!( {
656
+ if layout. abi. is_uninhabited( ) {
657
+ // Use this error even for the other intrinsics as it is more precise.
658
+ format!( "attempted to instantiate uninhabited type `{}`" , ty)
659
+ } else if intrinsic == sym:: assert_zero_valid {
660
+ format!( "attempted to zero-initialize type `{}`, which is invalid" , ty)
661
+ } else {
662
+ format!(
663
+ "attempted to leave type `{}` uninitialized, which is invalid" ,
664
+ ty
665
+ )
666
+ }
667
+ } )
683
668
} ) ;
669
+ crate :: base:: codegen_panic_nounwind ( fx, & msg_str, source_info) ;
684
670
return ;
685
671
}
686
672
}
0 commit comments