@@ -17,7 +17,7 @@ use rustc_hir::def_id::{DefId, DefIdMap};
1717use rustc_index::IndexVec;
1818use rustc_middle::mir;
1919use rustc_middle::ty::layout::{HasTypingEnv, LayoutOf};
20- use rustc_middle::ty::{self, GenericArgsRef, Instance, Ty, TypeVisitableExt};
20+ use rustc_middle::ty::{self, AssocItemContainer,  GenericArgsRef, Instance, Ty, TypeVisitableExt};
2121use rustc_session::Session;
2222use rustc_session::config::{self, DebugInfo};
2323use rustc_span::{
@@ -533,31 +533,29 @@ impl<'ll, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
533533            // First, let's see if this is a method within an inherent impl. Because
534534            // if yes, we want to make the result subroutine DIE a child of the
535535            // subroutine's self-type.
536-             if let Some(impl_def_id) = cx.tcx.impl_of_assoc(instance.def_id()) {
537-                 // If the method does *not* belong to a trait, proceed
538-                 if cx.tcx.trait_id_of_impl(impl_def_id).is_none() {
539-                     let impl_self_ty = cx.tcx.instantiate_and_normalize_erasing_regions(
540-                         instance.args,
541-                         cx.typing_env(),
542-                         cx.tcx.type_of(impl_def_id),
543-                     );
544- 
545-                     // Only "class" methods are generally understood by LLVM,
546-                     // so avoid methods on other types (e.g., `<*mut T>::null`).
547-                     if let ty::Adt(def, ..) = impl_self_ty.kind()
548-                         && !def.is_box()
549-                     {
550-                         // Again, only create type information if full debuginfo is enabled
551-                         if cx.sess().opts.debuginfo == DebugInfo::Full && !impl_self_ty.has_param()
552-                         {
553-                             return (type_di_node(cx, impl_self_ty), true);
554-                         } else {
555-                             return (namespace::item_namespace(cx, def.did()), false);
556-                         }
536+             if let Some(assoc) = cx.tcx.opt_associated_item(instance.def_id())
537+                 // For trait method impls we still use the "parallel namespace"
538+                 // strategy
539+                 && assoc.container == AssocItemContainer::InherentImpl
540+             {
541+                 let impl_def_id = cx.tcx.parent(instance.def_id());
542+                 let impl_self_ty = cx.tcx.instantiate_and_normalize_erasing_regions(
543+                     instance.args,
544+                     cx.typing_env(),
545+                     cx.tcx.type_of(impl_def_id),
546+                 );
547+ 
548+                 // Only "class" methods are generally understood by LLVM,
549+                 // so avoid methods on other types (e.g., `<*mut T>::null`).
550+                 if let ty::Adt(def, ..) = impl_self_ty.kind()
551+                     && !def.is_box()
552+                 {
553+                     // Again, only create type information if full debuginfo is enabled
554+                     if cx.sess().opts.debuginfo == DebugInfo::Full && !impl_self_ty.has_param() {
555+                         return (type_di_node(cx, impl_self_ty), true);
556+                     } else {
557+                         return (namespace::item_namespace(cx, def.did()), false);
557558                    }
558-                 } else {
559-                     // For trait method impls we still use the "parallel namespace"
560-                     // strategy
561559                }
562560            }
563561
0 commit comments