@@ -377,7 +377,6 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
377
377
ns : Namespace ,
378
378
module_id : DefId ,
379
379
item_name : Symbol ,
380
- item_str : & ' path str ,
381
380
) -> Result < ( Res , Option < String > ) , ErrorKind < ' path > > {
382
381
let tcx = self . cx . tcx ;
383
382
@@ -399,7 +398,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
399
398
. map ( |out| {
400
399
(
401
400
Res :: Primitive ( prim_ty) ,
402
- Some ( format ! ( "{}#{}.{}" , prim_ty. as_str( ) , out, item_str ) ) ,
401
+ Some ( format ! ( "{}#{}.{}" , prim_ty. as_str( ) , out, item_name ) ) ,
403
402
)
404
403
} )
405
404
} )
@@ -413,7 +412,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
413
412
ResolutionFailure :: NotResolved {
414
413
module_id,
415
414
partial_res : Some ( Res :: Primitive ( prim_ty) ) ,
416
- unresolved : item_str . into ( ) ,
415
+ unresolved : item_name . to_string ( ) . into ( ) ,
417
416
}
418
417
. into ( )
419
418
} )
@@ -490,8 +489,6 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
490
489
module_id : DefId ,
491
490
extra_fragment : & Option < String > ,
492
491
) -> Result < ( Res , Option < String > ) , ErrorKind < ' path > > {
493
- let tcx = self . cx . tcx ;
494
-
495
492
if let Some ( res) = self . resolve_path ( path_str, ns, module_id) {
496
493
match res {
497
494
// FIXME(#76467): make this fallthrough to lookup the associated
@@ -534,26 +531,39 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
534
531
}
535
532
} ) ?;
536
533
537
- let ty_res = if let Some ( ty_res) = self . resolve_path ( & path_root, TypeNS , module_id) {
538
- ty_res
539
- } else {
540
- // FIXME: this is duplicated on the end of this function.
541
- return if ns == Namespace :: ValueNS {
542
- self . variant_field ( path_str, module_id)
543
- } else {
544
- Err ( ResolutionFailure :: NotResolved {
545
- module_id,
546
- partial_res : None ,
547
- unresolved : path_root. into ( ) ,
534
+ self . resolve_path ( & path_root, TypeNS , module_id)
535
+ . and_then ( |ty_res| {
536
+ self . resolve_associated_item ( ty_res, item_name, ns, module_id, extra_fragment)
537
+ } )
538
+ . unwrap_or_else ( || {
539
+ if ns == Namespace :: ValueNS {
540
+ self . variant_field ( path_str, module_id)
541
+ } else {
542
+ Err ( ResolutionFailure :: NotResolved {
543
+ module_id,
544
+ partial_res : None ,
545
+ unresolved : path_root. into ( ) ,
546
+ }
547
+ . into ( ) )
548
548
}
549
- . into ( ) )
550
- } ;
551
- } ;
549
+ } )
550
+ }
552
551
553
- let res = match ty_res {
554
- Res :: Primitive ( prim) => Some (
555
- self . resolve_primitive_associated_item ( prim, ns, module_id, item_name, item_str) ,
556
- ) ,
552
+ fn resolve_associated_item (
553
+ & mut self ,
554
+ root_res : Res ,
555
+ item_name : Symbol ,
556
+ ns : Namespace ,
557
+ module_id : DefId ,
558
+ extra_fragment : & Option < String > ,
559
+ // lol this is so bad
560
+ ) -> Option < Result < ( Res , Option < String > ) , ErrorKind < ' static > > > {
561
+ let tcx = self . cx . tcx ;
562
+
563
+ match root_res {
564
+ Res :: Primitive ( prim) => {
565
+ Some ( self . resolve_primitive_associated_item ( prim, ns, module_id, item_name) )
566
+ }
557
567
Res :: Def (
558
568
DefKind :: Struct
559
569
| DefKind :: Union
@@ -597,13 +607,15 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
597
607
ty:: AssocKind :: Type => "associatedtype" ,
598
608
} ;
599
609
Some ( if extra_fragment. is_some ( ) {
600
- Err ( ErrorKind :: AnchorFailure ( AnchorFailure :: RustdocAnchorConflict ( ty_res) ) )
610
+ Err ( ErrorKind :: AnchorFailure ( AnchorFailure :: RustdocAnchorConflict (
611
+ root_res,
612
+ ) ) )
601
613
} else {
602
614
// HACK(jynelson): `clean` expects the type, not the associated item
603
615
// but the disambiguator logic expects the associated item.
604
616
// Store the kind in a side channel so that only the disambiguator logic looks at it.
605
617
self . kind_side_channel . set ( Some ( ( kind. as_def_kind ( ) , id) ) ) ;
606
- Ok ( ( ty_res , Some ( format ! ( "{}.{}" , out, item_str ) ) ) )
618
+ Ok ( ( root_res , Some ( format ! ( "{}.{}" , out, item_name ) ) ) )
607
619
} )
608
620
} else if ns == Namespace :: ValueNS {
609
621
debug ! ( "looking for variants or fields named {} for {:?}" , item_name, did) ;
@@ -634,7 +646,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
634
646
) )
635
647
} else {
636
648
Ok ( (
637
- ty_res ,
649
+ root_res ,
638
650
Some ( format ! (
639
651
"{}.{}" ,
640
652
if def. is_enum( ) { "variant" } else { "structfield" } ,
@@ -667,26 +679,16 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
667
679
} ;
668
680
669
681
if extra_fragment. is_some ( ) {
670
- Err ( ErrorKind :: AnchorFailure ( AnchorFailure :: RustdocAnchorConflict ( ty_res) ) )
682
+ Err ( ErrorKind :: AnchorFailure ( AnchorFailure :: RustdocAnchorConflict (
683
+ root_res,
684
+ ) ) )
671
685
} else {
672
686
let res = Res :: Def ( item. kind . as_def_kind ( ) , item. def_id ) ;
673
- Ok ( ( res, Some ( format ! ( "{}.{}" , kind, item_str ) ) ) )
687
+ Ok ( ( res, Some ( format ! ( "{}.{}" , kind, item_name ) ) ) )
674
688
}
675
689
} ) ,
676
690
_ => None ,
677
- } ;
678
- res. unwrap_or_else ( || {
679
- if ns == Namespace :: ValueNS {
680
- self . variant_field ( path_str, module_id)
681
- } else {
682
- Err ( ResolutionFailure :: NotResolved {
683
- module_id,
684
- partial_res : Some ( ty_res) ,
685
- unresolved : item_str. into ( ) ,
686
- }
687
- . into ( ) )
688
- }
689
- } )
691
+ }
690
692
}
691
693
692
694
/// Used for reporting better errors.
0 commit comments