@@ -684,27 +684,24 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
684684 if ns != Namespace :: ValueNS {
685685 return None ;
686686 }
687- debug ! ( "looking for variants or fields named {} for {:?}" , item_name, did) ;
687+ debug ! ( "looking for fields named {} for {:?}" , item_name, did) ;
688688 // 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 ,
690690 // not variant fields (2 path segments, not 3).
691691 let def = match tcx. type_of ( did) . kind ( ) {
692- ty:: Adt ( def, _) => def,
692+ ty:: Adt ( def, _) if !def . is_enum ( ) => def,
693693 _ => return None ,
694694 } ;
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+ ) )
708705 }
709706 Res :: Def ( DefKind :: Trait , did) => tcx
710707 . associated_items ( did)
0 commit comments