diff --git a/compiler/rustc_symbol_mangling/src/lib.rs b/compiler/rustc_symbol_mangling/src/lib.rs index 46f70bb1674..bed0e81e66e 100644 --- a/compiler/rustc_symbol_mangling/src/lib.rs +++ b/compiler/rustc_symbol_mangling/src/lib.rs @@ -155,6 +155,13 @@ pub fn typeid_for_fnabi<'tcx>(tcx: TyCtxt<'tcx>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) v0::mangle_typeid_for_fnabi(tcx, fn_abi) } +pub fn typeid_for_trait_ref<'tcx>( + tcx: TyCtxt<'tcx>, + trait_ref: ty::PolyExistentialTraitRef<'tcx>, +) -> String { + v0::mangle_typeid_for_trait_ref(tcx, trait_ref) +} + /// Computes the symbol name for the given instance. This function will call /// `compute_instantiating_crate` if it needs to factor the instantiating crate /// into the symbol name. diff --git a/compiler/rustc_symbol_mangling/src/v0.rs b/compiler/rustc_symbol_mangling/src/v0.rs index dc1946bcdc2..a00b86e79ac 100644 --- a/compiler/rustc_symbol_mangling/src/v0.rs +++ b/compiler/rustc_symbol_mangling/src/v0.rs @@ -95,6 +95,24 @@ pub(super) fn mangle_typeid_for_fnabi<'tcx>( format!("typeid{}", arg_count) } +pub(super) fn mangle_typeid_for_trait_ref<'tcx>( + tcx: TyCtxt<'tcx>, + trait_ref: ty::PolyExistentialTraitRef<'tcx>, +) -> String { + // FIXME(flip1995): See comment in `mangle_typeid_for_fnabi`. + let mut cx = &mut SymbolMangler { + tcx, + start_offset: 0, + paths: FxHashMap::default(), + types: FxHashMap::default(), + consts: FxHashMap::default(), + binders: vec![], + out: String::new(), + }; + cx = cx.print_def_path(trait_ref.def_id(), &[]).unwrap(); + std::mem::take(&mut cx.out) +} + struct BinderLevel { /// The range of distances from the root of what's /// being printed, to the lifetimes in a binder.