Skip to content

Commit

Permalink
Change generator_drop's instance to that of generator for dump_mir
Browse files Browse the repository at this point in the history
Otherwise the file name generated for generator_drop will become

core.ptr-drop_in_place.[generator@<FILEPATH>_<NUMBERS>].generator_drop.0.mir

instead of main-{closure#0}.generator_drop.0.mir which breaks a mir-opt
test.
  • Loading branch information
nbdd0121 committed Aug 18, 2023
1 parent eb4d6d9 commit 0a7202d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion compiler/rustc_mir_transform/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1151,8 +1151,11 @@ fn create_generator_drop_shim<'tcx>(
simplify::remove_dead_blocks(tcx, &mut body);

// Update the body's def to become the drop glue.
// This needs to be updated before the AbortUnwindingCalls pass.
let gen_instance = body.source.instance;
let drop_in_place = tcx.require_lang_item(LangItem::DropInPlace, None);
body.source.instance = InstanceDef::DropGlue(drop_in_place, Some(gen_ty));
let drop_instance = InstanceDef::DropGlue(drop_in_place, Some(gen_ty));
body.source.instance = drop_instance;

pm::run_passes_no_validate(
tcx,
Expand All @@ -1161,7 +1164,11 @@ fn create_generator_drop_shim<'tcx>(
None,
);

// Temporary change MirSource to generator's instance so that dump_mir produces more sensible
// filename.
body.source.instance = gen_instance;
dump_mir(tcx, false, "generator_drop", &0, &body, |_, _| Ok(()));
body.source.instance = drop_instance;

body
}
Expand Down

0 comments on commit 0a7202d

Please sign in to comment.