Skip to content

Commit fe82365

Browse files
committed
Fix MIR pretty printer for non-local DefIds
1 parent 7e0241c commit fe82365

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

compiler/rustc_mir/src/util/pretty.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -289,19 +289,19 @@ pub fn write_mir_pretty<'tcx>(
289289
}
290290
Ok(())
291291
};
292-
match tcx.hir().body_const_context(def_id.expect_local()) {
293-
None => render_body(w, tcx.optimized_mir(def_id))?,
294-
// For `const fn` we want to render the optimized MIR. If you want the mir used in
295-
// ctfe, you can dump the MIR after the `Deaggregator` optimization pass.
296-
Some(rustc_hir::ConstContext::ConstFn) => {
297-
render_body(w, tcx.optimized_mir(def_id))?;
298-
writeln!(w)?;
299-
writeln!(w, "// MIR FOR CTFE")?;
300-
// Do not use `render_body`, as that would render the promoteds again, but these
301-
// are shared between mir_for_ctfe and optimized_mir
302-
write_mir_fn(tcx, tcx.mir_for_ctfe(def_id), &mut |_, _| Ok(()), w)?;
303-
}
304-
Some(_) => render_body(w, tcx.mir_for_ctfe(def_id))?,
292+
293+
// For `const fn` we want to render both the optimized MIR and the MIR for ctfe.
294+
if tcx.is_const_fn_raw(def_id) {
295+
render_body(w, tcx.optimized_mir(def_id))?;
296+
writeln!(w)?;
297+
writeln!(w, "// MIR FOR CTFE")?;
298+
// Do not use `render_body`, as that would render the promoteds again, but these
299+
// are shared between mir_for_ctfe and optimized_mir
300+
write_mir_fn(tcx, tcx.mir_for_ctfe(def_id), &mut |_, _| Ok(()), w)?;
301+
} else {
302+
let instance_mir =
303+
tcx.instance_mir(ty::InstanceDef::Item(ty::WithOptConstParam::unknown(def_id)));
304+
render_body(w, instance_mir)?;
305305
}
306306
}
307307
Ok(())

0 commit comments

Comments
 (0)