Skip to content

Commit 9b99a58

Browse files
committed
Auto merge of rust-lang#108012 - compiler-errors:issue-107999, r=oli-obk
Don't ICE in `might_permit_raw_init` if reference is polymorphic Emitting optimized MIR for a polymorphic function may require computing layout of a type that isn't (yet) known. This happens in the instcombine pass, for example. Let's fail gracefully in that condition. cc `@saethlin` fixes rust-lang#107999
2 parents 14bc2e6 + c756108 commit 9b99a58

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/intrinsics/mod.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,8 @@ fn codegen_regular_intrinsic_call<'tcx>(
640640
sym::assert_inhabited | sym::assert_zero_valid | sym::assert_mem_uninitialized_valid => {
641641
intrinsic_args!(fx, args => (); intrinsic);
642642

643-
let layout = fx.layout_of(substs.type_at(0));
643+
let ty = substs.type_at(0);
644+
let layout = fx.layout_of(ty);
644645
if layout.abi.is_uninhabited() {
645646
with_no_trimmed_paths!({
646647
crate::base::codegen_panic_nounwind(
@@ -653,7 +654,10 @@ fn codegen_regular_intrinsic_call<'tcx>(
653654
}
654655

655656
if intrinsic == sym::assert_zero_valid
656-
&& !fx.tcx.permits_zero_init(fx.param_env().and(layout))
657+
&& !fx
658+
.tcx
659+
.permits_zero_init(fx.param_env().and(ty))
660+
.expect("expected to have layout during codegen")
657661
{
658662
with_no_trimmed_paths!({
659663
crate::base::codegen_panic_nounwind(
@@ -669,7 +673,10 @@ fn codegen_regular_intrinsic_call<'tcx>(
669673
}
670674

671675
if intrinsic == sym::assert_mem_uninitialized_valid
672-
&& !fx.tcx.permits_uninit_init(fx.param_env().and(layout))
676+
&& !fx
677+
.tcx
678+
.permits_uninit_init(fx.param_env().and(ty))
679+
.expect("expected to have layout during codegen")
673680
{
674681
with_no_trimmed_paths!({
675682
crate::base::codegen_panic_nounwind(

0 commit comments

Comments
 (0)