@@ -431,7 +431,6 @@ fn generate_item_def_id_path(
431431 original_def_id : DefId ,
432432 cx : & Context < ' _ > ,
433433 root_path : Option < & str > ,
434- original_def_kind : DefKind ,
435434) -> Result < HrefInfo , HrefError > {
436435 use rustc_middle:: traits:: ObligationCause ;
437436 use rustc_trait_selection:: infer:: TyCtxtInferExt ;
@@ -457,15 +456,14 @@ fn generate_item_def_id_path(
457456 let relative = clean:: inline:: item_relative_path ( tcx, def_id) ;
458457 let fqp: Vec < Symbol > = once ( crate_name) . chain ( relative) . collect ( ) ;
459458
460- let def_kind = tcx. def_kind ( def_id) ;
461- let shortty = def_kind. into ( ) ;
459+ let shortty = ItemType :: from_def_id ( def_id, tcx) ;
462460 let module_fqp = to_module_fqp ( shortty, & fqp) ;
463461 let mut is_remote = false ;
464462
465463 let url_parts = url_parts ( cx. cache ( ) , def_id, module_fqp, & cx. current , & mut is_remote) ?;
466464 let mut url_parts = make_href ( root_path, shortty, url_parts, & fqp, is_remote) ;
467465 if def_id != original_def_id {
468- let kind = ItemType :: from_def_kind ( original_def_kind , Some ( def_kind ) ) ;
466+ let kind = ItemType :: from_def_id ( original_def_id , tcx ) ;
469467 url_parts = format ! ( "{url_parts}#{kind}.{}" , tcx. item_name( original_def_id) )
470468 } ;
471469 Ok ( HrefInfo { url : url_parts, kind : shortty, rust_path : fqp } )
@@ -605,7 +603,7 @@ pub(crate) fn href_with_root_path(
605603 } else if did. is_local ( ) {
606604 return Err ( HrefError :: Private ) ;
607605 } else {
608- return generate_item_def_id_path ( did, original_did, cx, root_path, def_kind ) ;
606+ return generate_item_def_id_path ( did, original_did, cx, root_path) ;
609607 }
610608 }
611609 } ;
@@ -835,35 +833,35 @@ fn print_higher_ranked_params_with_space(
835833 } )
836834}
837835
836+ pub ( crate ) fn fragment ( did : DefId , tcx : TyCtxt < ' _ > ) -> String {
837+ let def_kind = tcx. def_kind ( did) ;
838+ match def_kind {
839+ DefKind :: AssocTy | DefKind :: AssocFn | DefKind :: AssocConst | DefKind :: Variant => {
840+ let item_type = ItemType :: from_def_id ( did, tcx) ;
841+ format ! ( "#{}.{}" , item_type. as_str( ) , tcx. item_name( did) )
842+ }
843+ DefKind :: Field => {
844+ let parent_def_id = tcx. parent ( did) ;
845+ let s;
846+ let kind = if tcx. def_kind ( parent_def_id) == DefKind :: Variant {
847+ s = format ! ( "variant.{}.field" , tcx. item_name( parent_def_id) . as_str( ) ) ;
848+ & s
849+ } else {
850+ "structfield"
851+ } ;
852+ format ! ( "#{kind}.{}" , tcx. item_name( did) )
853+ }
854+ _ => String :: new ( ) ,
855+ }
856+ }
857+
838858pub ( crate ) fn print_anchor ( did : DefId , text : Symbol , cx : & Context < ' _ > ) -> impl Display {
839859 fmt:: from_fn ( move |f| {
840860 if let Ok ( HrefInfo { url, kind, rust_path } ) = href ( did, cx) {
841- let tcx = cx. tcx ( ) ;
842- let def_kind = tcx. def_kind ( did) ;
843- let anchor = match def_kind {
844- DefKind :: AssocTy | DefKind :: AssocFn | DefKind :: AssocConst | DefKind :: Variant => {
845- let parent_def_id = tcx. parent ( did) ;
846- let item_type =
847- ItemType :: from_def_kind ( def_kind, Some ( tcx. def_kind ( parent_def_id) ) ) ;
848- format ! ( "#{}.{}" , item_type. as_str( ) , tcx. item_name( did) )
849- }
850- DefKind :: Field => {
851- let s;
852- let parent_id = tcx. parent ( did) ;
853- let kind = if tcx. def_kind ( parent_id) == DefKind :: Variant {
854- s = format ! ( "variant.{}.field" , tcx. item_name( parent_id) . as_str( ) ) ;
855- & s
856- } else {
857- "structfield"
858- } ;
859- format ! ( "#{kind}.{}" , tcx. item_name( did) )
860- }
861- _ => String :: new ( ) ,
862- } ;
863-
864861 write ! (
865862 f,
866863 r#"<a class="{kind}" href="{url}{anchor}" title="{kind} {path}">{text}</a>"# ,
864+ anchor = fragment( did, cx. tcx( ) ) ,
867865 path = join_path_syms( rust_path) ,
868866 text = EscapeBodyText ( text. as_str( ) ) ,
869867 )
0 commit comments