@@ -10,7 +10,7 @@ use rustc_hir::def::{
1010 PerNS ,
1111} ;
1212use rustc_hir:: def_id:: { CrateNum , DefId , CRATE_DEF_ID } ;
13- use rustc_middle:: ty:: { DefIdTree , Ty , TyCtxt } ;
13+ use rustc_middle:: ty:: { DefIdTree , Ty , TyCtxt , TyKind } ;
1414use rustc_middle:: { bug, span_bug, ty} ;
1515use rustc_session:: lint:: Lint ;
1616use rustc_span:: hygiene:: MacroKind ;
@@ -723,10 +723,27 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
723723 self . resolve_associated_item ( res, item_name, ns, module_id)
724724 }
725725 Res :: Def (
726- DefKind :: Struct | DefKind :: Union | DefKind :: Enum | DefKind :: ForeignTy ,
726+ def_kind @ ( DefKind :: Struct | DefKind :: Union | DefKind :: Enum | DefKind :: ForeignTy ) ,
727727 did,
728728 ) => {
729729 debug ! ( "looking for associated item named {} for item {:?}" , item_name, did) ;
730+ // Checks if item_name is a variant of the `SomeItem` enum
731+ if ns == TypeNS && def_kind == DefKind :: Enum {
732+ match tcx. type_of ( did) . kind ( ) {
733+ TyKind :: Adt ( adt_def, _) => {
734+ for variant in & adt_def. variants {
735+ if variant. name == item_name {
736+ return Some ( (
737+ root_res,
738+ ItemFragment ( FragmentKind :: Variant , variant. def_id ) ,
739+ ) ) ;
740+ }
741+ }
742+ }
743+ _ => unreachable ! ( ) ,
744+ }
745+ }
746+
730747 // Checks if item_name belongs to `impl SomeItem`
731748 let assoc_item = tcx
732749 . inherent_impls ( did)
0 commit comments