@@ -377,7 +377,6 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
377377 ns : Namespace ,
378378 module_id : DefId ,
379379 item_name : Symbol ,
380- item_str : & ' path str ,
381380 ) -> Result < ( Res , Option < String > ) , ErrorKind < ' path > > {
382381 let tcx = self . cx . tcx ;
383382
@@ -399,7 +398,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
399398 . map ( |out| {
400399 (
401400 Res :: Primitive ( prim_ty) ,
402- Some ( format ! ( "{}#{}.{}" , prim_ty. as_str( ) , out, item_str ) ) ,
401+ Some ( format ! ( "{}#{}.{}" , prim_ty. as_str( ) , out, item_name ) ) ,
403402 )
404403 } )
405404 } )
@@ -413,7 +412,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
413412 ResolutionFailure :: NotResolved {
414413 module_id,
415414 partial_res : Some ( Res :: Primitive ( prim_ty) ) ,
416- unresolved : item_str . into ( ) ,
415+ unresolved : item_name . to_string ( ) . into ( ) ,
417416 }
418417 . into ( )
419418 } )
@@ -490,8 +489,6 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
490489 module_id : DefId ,
491490 extra_fragment : & Option < String > ,
492491 ) -> Result < ( Res , Option < String > ) , ErrorKind < ' path > > {
493- let tcx = self . cx . tcx ;
494-
495492 if let Some ( res) = self . resolve_path ( path_str, ns, module_id) {
496493 match res {
497494 // FIXME(#76467): make this fallthrough to lookup the associated
@@ -534,26 +531,39 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
534531 }
535532 } ) ?;
536533
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 ( ) )
548548 }
549- . into ( ) )
550- } ;
551- } ;
549+ } )
550+ }
552551
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+ }
557567 Res :: Def (
558568 DefKind :: Struct
559569 | DefKind :: Union
@@ -597,13 +607,15 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
597607 ty:: AssocKind :: Type => "associatedtype" ,
598608 } ;
599609 Some ( if extra_fragment. is_some ( ) {
600- Err ( ErrorKind :: AnchorFailure ( AnchorFailure :: RustdocAnchorConflict ( ty_res) ) )
610+ Err ( ErrorKind :: AnchorFailure ( AnchorFailure :: RustdocAnchorConflict (
611+ root_res,
612+ ) ) )
601613 } else {
602614 // HACK(jynelson): `clean` expects the type, not the associated item
603615 // but the disambiguator logic expects the associated item.
604616 // Store the kind in a side channel so that only the disambiguator logic looks at it.
605617 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 ) ) ) )
607619 } )
608620 } else if ns == Namespace :: ValueNS {
609621 debug ! ( "looking for variants or fields named {} for {:?}" , item_name, did) ;
@@ -634,7 +646,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
634646 ) )
635647 } else {
636648 Ok ( (
637- ty_res ,
649+ root_res ,
638650 Some ( format ! (
639651 "{}.{}" ,
640652 if def. is_enum( ) { "variant" } else { "structfield" } ,
@@ -667,26 +679,16 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
667679 } ;
668680
669681 if extra_fragment. is_some ( ) {
670- Err ( ErrorKind :: AnchorFailure ( AnchorFailure :: RustdocAnchorConflict ( ty_res) ) )
682+ Err ( ErrorKind :: AnchorFailure ( AnchorFailure :: RustdocAnchorConflict (
683+ root_res,
684+ ) ) )
671685 } else {
672686 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 ) ) ) )
674688 }
675689 } ) ,
676690 _ => 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+ }
690692 }
691693
692694 /// Used for reporting better errors.
0 commit comments