@@ -10,7 +10,7 @@ use rustc_hir::def::{
10
10
PerNS ,
11
11
} ;
12
12
use 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 } ;
14
14
use rustc_middle:: { bug, span_bug, ty} ;
15
15
use rustc_session:: lint:: Lint ;
16
16
use rustc_span:: hygiene:: MacroKind ;
@@ -723,10 +723,27 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
723
723
self . resolve_associated_item ( res, item_name, ns, module_id)
724
724
}
725
725
Res :: Def (
726
- DefKind :: Struct | DefKind :: Union | DefKind :: Enum | DefKind :: ForeignTy ,
726
+ def_kind @ ( DefKind :: Struct | DefKind :: Union | DefKind :: Enum | DefKind :: ForeignTy ) ,
727
727
did,
728
728
) => {
729
729
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
+
730
747
// Checks if item_name belongs to `impl SomeItem`
731
748
let assoc_item = tcx
732
749
. inherent_impls ( did)
0 commit comments