@@ -611,7 +611,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
611
611
ty:: AssocKind :: Const => "associatedconstant" ,
612
612
ty:: AssocKind :: Type => "associatedtype" ,
613
613
} ;
614
- Some ( if extra_fragment. is_some ( ) {
614
+ return Some ( if extra_fragment. is_some ( ) {
615
615
Err ( ErrorKind :: AnchorFailure ( AnchorFailure :: RustdocAnchorConflict (
616
616
root_res,
617
617
) ) )
@@ -621,51 +621,41 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
621
621
// Store the kind in a side channel so that only the disambiguator logic looks at it.
622
622
self . kind_side_channel . set ( Some ( ( kind. as_def_kind ( ) , id) ) ) ;
623
623
Ok ( ( root_res, Some ( format ! ( "{}.{}" , out, item_name) ) ) )
624
- } )
625
- } else if ns == Namespace :: ValueNS {
626
- debug ! ( "looking for variants or fields named {} for {:?}" , item_name, did) ;
627
- // FIXME(jynelson): why is this different from
628
- // `variant_field`?
629
- match tcx. type_of ( did) . kind ( ) {
630
- ty:: Adt ( def, _) => {
631
- let field = if def. is_enum ( ) {
632
- def. all_fields ( ) . find ( |item| item. ident . name == item_name)
633
- } else {
634
- def. non_enum_variant ( )
635
- . fields
636
- . iter ( )
637
- . find ( |item| item. ident . name == item_name)
638
- } ;
639
- field. map ( |item| {
640
- if extra_fragment. is_some ( ) {
641
- let res = Res :: Def (
642
- if def. is_enum ( ) {
643
- DefKind :: Variant
644
- } else {
645
- DefKind :: Field
646
- } ,
647
- item. did ,
648
- ) ;
649
- Err ( ErrorKind :: AnchorFailure (
650
- AnchorFailure :: RustdocAnchorConflict ( res) ,
651
- ) )
652
- } else {
653
- Ok ( (
654
- root_res,
655
- Some ( format ! (
656
- "{}.{}" ,
657
- if def. is_enum( ) { "variant" } else { "structfield" } ,
658
- item. ident
659
- ) ) ,
660
- ) )
661
- }
662
- } )
663
- }
664
- _ => None ,
665
- }
666
- } else {
667
- None
624
+ } ) ;
625
+ }
626
+
627
+ if ns != Namespace :: ValueNS {
628
+ return None ;
668
629
}
630
+ debug ! ( "looking for variants or fields named {} for {:?}" , item_name, did) ;
631
+ // FIXME: this doesn't really belong in `associated_item` (maybe `variant_field` is better?)
632
+ // NOTE: it's different from variant_field because it resolves fields and variants,
633
+ // not variant fields (2 path segments, not 3).
634
+ let def = match tcx. type_of ( did) . kind ( ) {
635
+ ty:: Adt ( def, _) => def,
636
+ _ => return None ,
637
+ } ;
638
+ let field = if def. is_enum ( ) {
639
+ def. all_fields ( ) . find ( |item| item. ident . name == item_name)
640
+ } else {
641
+ def. non_enum_variant ( ) . fields . iter ( ) . find ( |item| item. ident . name == item_name)
642
+ } ?;
643
+ Some ( if extra_fragment. is_some ( ) {
644
+ let res = Res :: Def (
645
+ if def. is_enum ( ) { DefKind :: Variant } else { DefKind :: Field } ,
646
+ field. did ,
647
+ ) ;
648
+ Err ( ErrorKind :: AnchorFailure ( AnchorFailure :: RustdocAnchorConflict ( res) ) )
649
+ } else {
650
+ Ok ( (
651
+ root_res,
652
+ Some ( format ! (
653
+ "{}.{}" ,
654
+ if def. is_enum( ) { "variant" } else { "structfield" } ,
655
+ field. ident
656
+ ) ) ,
657
+ ) )
658
+ } )
669
659
}
670
660
Res :: Def ( DefKind :: Trait , did) => tcx
671
661
. associated_items ( did)
0 commit comments