From 0bf75fbfc8812ed0c7dc827def29c9d65a438eac Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Sat, 12 Dec 2020 16:51:11 +0100 Subject: [PATCH 1/2] Use better symbol names for the drop glue --- compiler/rustc_symbol_mangling/src/legacy.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/compiler/rustc_symbol_mangling/src/legacy.rs b/compiler/rustc_symbol_mangling/src/legacy.rs index eba8e1a0613..60b60db6493 100644 --- a/compiler/rustc_symbol_mangling/src/legacy.rs +++ b/compiler/rustc_symbol_mangling/src/legacy.rs @@ -55,6 +55,26 @@ pub(super) fn mangle( let hash = get_symbol_hash(tcx, instance, instance_ty, instantiating_crate); + if let ty::InstanceDef::DropGlue(_drop_in_place, ty) = instance.def { + // Use `{{drop}}::<$TYPE>::$hash` as name for the drop glue instead of + // `core::mem::drop_in_place::$hash`. + let mut printer = + SymbolPrinter { tcx, path: SymbolPath::new(), keep_within_component: false }; + printer.write_str("{{drop}}").unwrap(); + printer.path.finalize_pending_component(); + let printer = printer + .generic_delimiters(|mut printer| { + if let Some(ty) = ty { + printer.print_type(ty) + } else { + printer.write_str("_")?; + Ok(printer) + } + }) + .unwrap(); + return printer.path.finish(hash); + } + let mut printer = SymbolPrinter { tcx, path: SymbolPath::new(), keep_within_component: false } .print_def_path(def_id, &[]) .unwrap(); From 4a48d680f2a27d3aff5507e973035681a2bec854 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 17 Dec 2020 09:57:48 +0100 Subject: [PATCH 2/2] Simplify based on eddyb's comment --- compiler/rustc_symbol_mangling/src/legacy.rs | 30 ++++++-------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/compiler/rustc_symbol_mangling/src/legacy.rs b/compiler/rustc_symbol_mangling/src/legacy.rs index 60b60db6493..fd35915f644 100644 --- a/compiler/rustc_symbol_mangling/src/legacy.rs +++ b/compiler/rustc_symbol_mangling/src/legacy.rs @@ -55,28 +55,16 @@ pub(super) fn mangle( let hash = get_symbol_hash(tcx, instance, instance_ty, instantiating_crate); - if let ty::InstanceDef::DropGlue(_drop_in_place, ty) = instance.def { - // Use `{{drop}}::<$TYPE>::$hash` as name for the drop glue instead of - // `core::mem::drop_in_place::$hash`. - let mut printer = - SymbolPrinter { tcx, path: SymbolPath::new(), keep_within_component: false }; - printer.write_str("{{drop}}").unwrap(); - printer.path.finalize_pending_component(); - let printer = printer - .generic_delimiters(|mut printer| { - if let Some(ty) = ty { - printer.print_type(ty) - } else { - printer.write_str("_")?; - Ok(printer) - } - }) - .unwrap(); - return printer.path.finish(hash); - } - let mut printer = SymbolPrinter { tcx, path: SymbolPath::new(), keep_within_component: false } - .print_def_path(def_id, &[]) + .print_def_path( + def_id, + if let ty::InstanceDef::DropGlue(_, _) = instance.def { + // Add the name of the dropped type to the symbol name + &*instance.substs + } else { + &[] + }, + ) .unwrap(); if let ty::InstanceDef::VtableShim(..) = instance.def {