@@ -684,27 +684,24 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
684
684
if ns != Namespace :: ValueNS {
685
685
return None ;
686
686
}
687
- debug ! ( "looking for variants or fields named {} for {:?}" , item_name, did) ;
687
+ debug ! ( "looking for fields named {} for {:?}" , item_name, did) ;
688
688
// FIXME: this doesn't really belong in `associated_item` (maybe `variant_field` is better?)
689
- // NOTE: it's different from variant_field because it resolves fields and variants ,
689
+ // NOTE: it's different from variant_field because it only resolves struct fields ,
690
690
// not variant fields (2 path segments, not 3).
691
691
let def = match tcx. type_of ( did) . kind ( ) {
692
- ty:: Adt ( def, _) => def,
692
+ ty:: Adt ( def, _) if !def . is_enum ( ) => def,
693
693
_ => return None ,
694
694
} ;
695
- let field = if def. is_enum ( ) {
696
- def. all_fields ( ) . find ( |item| item. ident . name == item_name)
697
- } else {
698
- def. non_enum_variant ( ) . fields . iter ( ) . find ( |item| item. ident . name == item_name)
699
- } ?;
700
- let kind = if def. is_enum ( ) { DefKind :: Variant } else { DefKind :: Field } ;
701
- let fragment = if def. is_enum ( ) {
702
- // FIXME: how can the field be a variant?
703
- UrlFragment :: Variant ( field. ident . name )
704
- } else {
705
- UrlFragment :: StructField ( field. ident . name )
706
- } ;
707
- Some ( ( root_res, fragment, Some ( ( kind, field. did ) ) ) )
695
+ let field = def
696
+ . non_enum_variant ( )
697
+ . fields
698
+ . iter ( )
699
+ . find ( |item| item. ident . name == item_name) ?;
700
+ Some ( (
701
+ root_res,
702
+ UrlFragment :: StructField ( field. ident . name ) ,
703
+ Some ( ( DefKind :: Field , field. did ) ) ,
704
+ ) )
708
705
}
709
706
Res :: Def ( DefKind :: Trait , did) => tcx
710
707
. associated_items ( did)
0 commit comments