about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src
diff options
context:
space:
mode:
authorBen Kimock <kimockb@gmail.com>2023-01-22 17:06:28 -0500
committerBen Kimock <kimockb@gmail.com>2023-01-23 19:25:10 -0500
commit5bfad5cc858d3b59d30da6d411449883581ff510 (patch)
treedb1f27a6c8ba169461b42407154dfe65c3839a04 /compiler/rustc_mir_transform/src
parent662199f125005dca31bf9cdfa298bd5a7994e07c (diff)
downloadrust-5bfad5cc858d3b59d30da6d411449883581ff510.tar.gz
rust-5bfad5cc858d3b59d30da6d411449883581ff510.zip
Thread a ParamEnv down to might_permit_raw_init
Diffstat (limited to 'compiler/rustc_mir_transform/src')
-rw-r--r--compiler/rustc_mir_transform/src/instcombine.rs23
1 files changed, 15 insertions, 8 deletions
diff --git a/compiler/rustc_mir_transform/src/instcombine.rs b/compiler/rustc_mir_transform/src/instcombine.rs
index 1b795479a92..e1faa7a08d9 100644
--- a/compiler/rustc_mir_transform/src/instcombine.rs
+++ b/compiler/rustc_mir_transform/src/instcombine.rs
@@ -6,7 +6,7 @@ use rustc_middle::mir::{
     BinOp, Body, Constant, ConstantKind, LocalDecls, Operand, Place, ProjectionElem, Rvalue,
     SourceInfo, Statement, StatementKind, Terminator, TerminatorKind, UnOp,
 };
-use rustc_middle::ty::{self, layout::TyAndLayout, ParamEnv, SubstsRef, Ty, TyCtxt};
+use rustc_middle::ty::{self, layout::TyAndLayout, ParamEnv, ParamEnvAnd, SubstsRef, Ty, TyCtxt};
 use rustc_span::symbol::{sym, Symbol};
 
 pub struct InstCombine;
@@ -231,7 +231,7 @@ impl<'tcx> InstCombineContext<'tcx, '_> {
         // Check this is a foldable intrinsic before we query the layout of our generic parameter
         let Some(assert_panics) = intrinsic_assert_panics(intrinsic_name) else { return; };
         let Ok(layout) = self.tcx.layout_of(self.param_env.and(ty)) else { return; };
-        if assert_panics(self.tcx, layout) {
+        if assert_panics(self.tcx, self.param_env.and(layout)) {
             // If we know the assert panics, indicate to later opts that the call diverges
             *target = None;
         } else {
@@ -243,18 +243,25 @@ impl<'tcx> InstCombineContext<'tcx, '_> {
 
 fn intrinsic_assert_panics<'tcx>(
     intrinsic_name: Symbol,
-) -> Option<fn(TyCtxt<'tcx>, TyAndLayout<'tcx>) -> bool> {
-    fn inhabited_predicate<'tcx>(_tcx: TyCtxt<'tcx>, layout: TyAndLayout<'tcx>) -> bool {
+) -> Option<fn(TyCtxt<'tcx>, ParamEnvAnd<'tcx, TyAndLayout<'tcx>>) -> bool> {
+    fn inhabited_predicate<'tcx>(
+        _tcx: TyCtxt<'tcx>,
+        param_env_and_layout: ParamEnvAnd<'tcx, TyAndLayout<'tcx>>,
+    ) -> bool {
+        let (_param_env, layout) = param_env_and_layout.into_parts();
         layout.abi.is_uninhabited()
     }
-    fn zero_valid_predicate<'tcx>(tcx: TyCtxt<'tcx>, layout: TyAndLayout<'tcx>) -> bool {
-        !tcx.permits_zero_init(layout)
+    fn zero_valid_predicate<'tcx>(
+        tcx: TyCtxt<'tcx>,
+        param_env_and_layout: ParamEnvAnd<'tcx, TyAndLayout<'tcx>>,
+    ) -> bool {
+        !tcx.permits_zero_init(param_env_and_layout)
     }
     fn mem_uninitialized_valid_predicate<'tcx>(
         tcx: TyCtxt<'tcx>,
-        layout: TyAndLayout<'tcx>,
+        param_env_and_layout: ParamEnvAnd<'tcx, TyAndLayout<'tcx>>,
     ) -> bool {
-        !tcx.permits_uninit_init(layout)
+        !tcx.permits_uninit_init(param_env_and_layout)
     }
 
     match intrinsic_name {