From 0a7202d4769fe417988b7e74333e3014a51ad462 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Fri, 18 Aug 2023 16:36:22 +0100 Subject: [PATCH] Change generator_drop's instance to that of generator for dump_mir Otherwise the file name generated for generator_drop will become core.ptr-drop_in_place.[generator@_].generator_drop.0.mir instead of main-{closure#0}.generator_drop.0.mir which breaks a mir-opt test. --- compiler/rustc_mir_transform/src/generator.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_mir_transform/src/generator.rs b/compiler/rustc_mir_transform/src/generator.rs index 2bd759ab1e5dc..ff4822f333f08 100644 --- a/compiler/rustc_mir_transform/src/generator.rs +++ b/compiler/rustc_mir_transform/src/generator.rs @@ -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, @@ -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 }