about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-02-15 20:56:07 +0000
committerbors <bors@rust-lang.org>2023-02-15 20:56:07 +0000
commitc5283576ec18937d98889679a54aa8f2dee2b875 (patch)
tree950ca5fd9d874fa9f7c990eee71df8a14e5ee58c /compiler/rustc_codegen_ssa/src
parent2d14db321b043ffc579a7461464c88d7e3f54f83 (diff)
parentb096f0e0f01f9cc1f13d4d664fda93f9efe95485 (diff)
downloadrust-c5283576ec18937d98889679a54aa8f2dee2b875.tar.gz
rust-c5283576ec18937d98889679a54aa8f2dee2b875.zip
Auto merge of #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 #107999
Diffstat (limited to 'compiler/rustc_codegen_ssa/src')
-rw-r--r--compiler/rustc_codegen_ssa/src/mir/block.rs10
1 files changed, 8 insertions, 2 deletions
diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs
index 2623a650e07..9af408646ae 100644
--- a/compiler/rustc_codegen_ssa/src/mir/block.rs
+++ b/compiler/rustc_codegen_ssa/src/mir/block.rs
@@ -674,8 +674,14 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
             let layout = bx.layout_of(ty);
             let do_panic = match intrinsic {
                 Inhabited => layout.abi.is_uninhabited(),
-                ZeroValid => !bx.tcx().permits_zero_init(bx.param_env().and(layout)),
-                MemUninitializedValid => !bx.tcx().permits_uninit_init(bx.param_env().and(layout)),
+                ZeroValid => !bx
+                    .tcx()
+                    .permits_zero_init(bx.param_env().and(ty))
+                    .expect("expected to have layout during codegen"),
+                MemUninitializedValid => !bx
+                    .tcx()
+                    .permits_uninit_init(bx.param_env().and(ty))
+                    .expect("expected to have layout during codegen"),
             };
             Some(if do_panic {
                 let msg_str = with_no_visible_paths!({