Change:
} Ok(()) }; <del> 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))?, </del> <ins> // 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)?; </ins> } } Ok(())

Discussion:
The expectlocal call here means that writemirpretty no longer works for non local defids. The ability to print out MIR for non local functions this way is critical for the MIRAI project. Originally posted by in <!-- TRIAGEBOTSTART --<!-- TRIAGEBOTASSIGNSTART --<!-- TRIAGEBOTASSIGNDATASTARTTRIAGEBOTASSIGNDATAEND --<!-- TRIAGEBOTASSIGNEND --<!-- TRIAGEBOTEND --
Cc
I think what we can do is to check for the path, and use if it is not a const fn, as already does the correct dispatching for anything that is not a const fn.
Can I working on this?
That would be great. This is a blocker for me.
It's all yours! You can use to have the bot assign it to you
claim
If you need any help, don't hesitate to ask here or ping me on zulip. I'll respond whenever I have time (which is a bit flaky this week, but you should definitely get a response once a day)
Sorry, I haven't had time to finish it lately. Let's see if others can help.
Do we have a reproducer for this issue? I have some idea of what needs to be done here, but I don't know how to check if it really works.
The only way I know of how to do this is to write something that uses the compiler driver, see for example: That seems like quite a lot of trouble to go to. More ideal would be some kind of unit test, but I have no idea of how that may be accomplished. Perhaps the easiest way to do an ad hoc test would be to build MIRAI with the latest nightly (I'd have to put up a branch that has been ported to it) and then run its tests.
I've uploaded a draft PR to If you build that with a recent nightly and then run cargo test, you should see failures. If your fix is good, then all tests should pass.
Thanks that's very helpful. I was able to run the tests successfully using the master branch, but if I use my stage 1 build with your branch some of the tests fail, and the backtraces include so I'm guessing those failing tests are reproducers for this issue.