Skip to content

Commit 760f80c

Browse files
committed
enable extra comments in NLL MIR dumps
1 parent 88ecb2d commit 760f80c

File tree

1 file changed

+34
-21
lines changed
  • compiler/rustc_borrowck/src

1 file changed

+34
-21
lines changed

compiler/rustc_borrowck/src/nll.rs

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use polonius_engine::{Algorithm, Output};
99
use rustc_data_structures::fx::FxIndexMap;
1010
use rustc_hir::def_id::LocalDefId;
1111
use rustc_index::IndexSlice;
12+
use rustc_middle::mir::pretty::{dump_mir_with_options, PrettyPrintMirOptions};
1213
use rustc_middle::mir::{
1314
create_dump_file, dump_enabled, dump_mir, Body, ClosureOutlivesSubject,
1415
ClosureRegionRequirements, PassWhere, Promoted,
@@ -218,32 +219,44 @@ pub(super) fn dump_mir_results<'tcx>(
218219
return;
219220
}
220221

221-
dump_mir(infcx.tcx, false, "nll", &0, body, |pass_where, out| {
222-
match pass_where {
223-
// Before the CFG, dump out the values for each region variable.
224-
PassWhere::BeforeCFG => {
225-
regioncx.dump_mir(infcx.tcx, out)?;
226-
writeln!(out, "|")?;
227-
228-
if let Some(closure_region_requirements) = closure_region_requirements {
229-
writeln!(out, "| Free Region Constraints")?;
230-
for_each_region_constraint(
231-
infcx.tcx,
232-
closure_region_requirements,
233-
&mut |msg| writeln!(out, "| {msg}"),
234-
)?;
222+
// We want the NLL extra comments printed by default in NLL MIR dumps (they were removed in
223+
// #112346). Specifying `-Z mir-include-spans` on the CLI still has priority: for example,
224+
// they're always disabled in mir-opt tests to make working with blessed dumps easier.
225+
let options = PrettyPrintMirOptions::from_cli_with_default(infcx.tcx, true);
226+
dump_mir_with_options(
227+
infcx.tcx,
228+
false,
229+
"nll",
230+
&0,
231+
body,
232+
|pass_where, out| {
233+
match pass_where {
234+
// Before the CFG, dump out the values for each region variable.
235+
PassWhere::BeforeCFG => {
236+
regioncx.dump_mir(infcx.tcx, out)?;
235237
writeln!(out, "|")?;
238+
239+
if let Some(closure_region_requirements) = closure_region_requirements {
240+
writeln!(out, "| Free Region Constraints")?;
241+
for_each_region_constraint(
242+
infcx.tcx,
243+
closure_region_requirements,
244+
&mut |msg| writeln!(out, "| {msg}"),
245+
)?;
246+
writeln!(out, "|")?;
247+
}
236248
}
237-
}
238249

239-
PassWhere::BeforeLocation(_) => {}
250+
PassWhere::BeforeLocation(_) => {}
240251

241-
PassWhere::AfterTerminator(_) => {}
252+
PassWhere::AfterTerminator(_) => {}
242253

243-
PassWhere::BeforeBlock(_) | PassWhere::AfterLocation(_) | PassWhere::AfterCFG => {}
244-
}
245-
Ok(())
246-
});
254+
PassWhere::BeforeBlock(_) | PassWhere::AfterLocation(_) | PassWhere::AfterCFG => {}
255+
}
256+
Ok(())
257+
},
258+
options,
259+
);
247260

248261
// Also dump the inference graph constraints as a graphviz file.
249262
let _: io::Result<()> = try {

0 commit comments

Comments
 (0)