@@ -273,25 +273,35 @@ pub fn write_mir_pretty<'tcx>(
273273
274274 let mut first = true ;
275275 for def_id in dump_mir_def_ids ( tcx, single) {
276- let body = match tcx. hir ( ) . body_const_context ( def_id. expect_local ( ) ) {
277- // For `const fn` we want to render the optimized MIR. If you want the mir used in
278- // ctfe, you can dump the MIR after the `Deaggregator` optimization pass.
279- None | Some ( rustc_hir:: ConstContext :: ConstFn ) => tcx. optimized_mir ( def_id) ,
280- Some ( _) => tcx. mir_for_ctfe ( def_id) ,
281- } ;
282-
283276 if first {
284277 first = false ;
285278 } else {
286279 // Put empty lines between all items
287280 writeln ! ( w) ?;
288281 }
289282
290- write_mir_fn ( tcx, body, & mut |_, _| Ok ( ( ) ) , w) ?;
291-
292- for body in tcx. promoted_mir ( def_id) {
293- writeln ! ( w) ?;
283+ let render_body = |w : & mut dyn Write , body| -> io:: Result < ( ) > {
294284 write_mir_fn ( tcx, body, & mut |_, _| Ok ( ( ) ) , w) ?;
285+
286+ for body in tcx. promoted_mir ( def_id) {
287+ writeln ! ( w) ?;
288+ write_mir_fn ( tcx, body, & mut |_, _| Ok ( ( ) ) , w) ?;
289+ }
290+ Ok ( ( ) )
291+ } ;
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) ) ?,
295305 }
296306 }
297307 Ok ( ( ) )
0 commit comments