about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_mir/src/transform/inline.rs3
-rw-r--r--compiler/rustc_mir/src/transform/mod.rs7
2 files changed, 9 insertions, 1 deletions
diff --git a/compiler/rustc_mir/src/transform/inline.rs b/compiler/rustc_mir/src/transform/inline.rs
index e157ef9c682..dd9a514466d 100644
--- a/compiler/rustc_mir/src/transform/inline.rs
+++ b/compiler/rustc_mir/src/transform/inline.rs
@@ -39,6 +39,9 @@ struct CallSite<'tcx> {
 
 impl<'tcx> MirPass<'tcx> for Inline {
     fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
+        // If you change this optimization level, also change the level in
+        // `mir_drops_elaborated_and_const_checked` for the call to `mir_inliner_callees`.
+        // Otherwise you will get an ICE about stolen MIR.
         if tcx.sess.opts.debugging_opts.mir_opt_level < 2 {
             return;
         }
diff --git a/compiler/rustc_mir/src/transform/mod.rs b/compiler/rustc_mir/src/transform/mod.rs
index ea62f9a8f95..2786127513d 100644
--- a/compiler/rustc_mir/src/transform/mod.rs
+++ b/compiler/rustc_mir/src/transform/mod.rs
@@ -425,7 +425,12 @@ fn mir_drops_elaborated_and_const_checked<'tcx>(
     if is_fn_like {
         let did = def.did.to_def_id();
         let def = ty::WithOptConstParam::unknown(did);
-        let _ = tcx.mir_inliner_callees(ty::InstanceDef::Item(def));
+
+        // Do not compute the mir call graph without said call graph actually being used.
+        // Keep this in sync with the mir inliner's optimization level.
+        if tcx.sess.opts.debugging_opts.mir_opt_level >= 2 {
+            let _ = tcx.mir_inliner_callees(ty::InstanceDef::Item(def));
+        }
     }
 
     let (body, _) = tcx.mir_promoted(def);