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