diff options
| author | Dylan DPC <dylan.dpc@gmail.com> | 2021-02-14 16:54:51 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-14 16:54:51 +0100 |
| commit | 2efde8c79505b4d53490befe2247d0f974cfe2a0 (patch) | |
| tree | a6f1d50fede38b53a52d45a2f8867bb2a0674052 | |
| parent | 91889fc5554970aa0752e18ff5cf0ce52d964aac (diff) | |
| parent | fe82365630a5bb8a785cc1601248cc996c82c37a (diff) | |
| download | rust-2efde8c79505b4d53490befe2247d0f974cfe2a0.tar.gz rust-2efde8c79505b4d53490befe2247d0f974cfe2a0.zip | |
Rollup merge of #81965 - osa1:issue81200, r=oli-obk
Fix MIR pretty printer for non-local DefIds Tries to fix #81200 -- the reproducer in the issue is not fixed yet. Submitting PR to get feedback. r? oli-obk
| -rw-r--r-- | compiler/rustc_mir/src/util/pretty.rs | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/compiler/rustc_mir/src/util/pretty.rs b/compiler/rustc_mir/src/util/pretty.rs index 7fc1c3a73af..f46e94eea96 100644 --- a/compiler/rustc_mir/src/util/pretty.rs +++ b/compiler/rustc_mir/src/util/pretty.rs @@ -289,19 +289,19 @@ pub fn write_mir_pretty<'tcx>( } Ok(()) }; - match tcx.hir().body_const_context(def_id.expect_local()) { - None => render_body(w, tcx.optimized_mir(def_id))?, - // For `const fn` we want to render the optimized MIR. If you want the mir used in - // ctfe, you can dump the MIR after the `Deaggregator` optimization pass. - Some(rustc_hir::ConstContext::ConstFn) => { - render_body(w, tcx.optimized_mir(def_id))?; - writeln!(w)?; - writeln!(w, "// MIR FOR CTFE")?; - // Do not use `render_body`, as that would render the promoteds again, but these - // are shared between mir_for_ctfe and optimized_mir - write_mir_fn(tcx, tcx.mir_for_ctfe(def_id), &mut |_, _| Ok(()), w)?; - } - Some(_) => render_body(w, tcx.mir_for_ctfe(def_id))?, + + // For `const fn` we want to render both the optimized MIR and the MIR for ctfe. + if tcx.is_const_fn_raw(def_id) { + render_body(w, tcx.optimized_mir(def_id))?; + writeln!(w)?; + writeln!(w, "// MIR FOR CTFE")?; + // Do not use `render_body`, as that would render the promoteds again, but these + // are shared between mir_for_ctfe and optimized_mir + write_mir_fn(tcx, tcx.mir_for_ctfe(def_id), &mut |_, _| Ok(()), w)?; + } else { + let instance_mir = + tcx.instance_mir(ty::InstanceDef::Item(ty::WithOptConstParam::unknown(def_id))); + render_body(w, instance_mir)?; } } Ok(()) |
