@@ -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,26 +833,36 @@ fn print_higher_ranked_params_with_space(
835833 } )
836834}
837835
838- pub ( crate ) fn print_anchor ( did : DefId , text : Symbol , cx : & Context < ' _ > ) -> impl Display {
836+ pub ( crate ) fn fragment ( did : DefId , tcx : TyCtxt < ' _ > ) -> impl Display {
839837 fmt:: from_fn ( move |f| {
840- 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 = if matches ! (
844- def_kind ,
845- DefKind :: AssocTy | DefKind :: AssocFn | DefKind :: AssocConst | DefKind :: Variant
846- ) {
838+ let def_kind = tcx . def_kind ( did) ;
839+ match def_kind {
840+ DefKind :: AssocTy | DefKind :: AssocFn | DefKind :: AssocConst | DefKind :: Variant => {
841+ let item_type = ItemType :: from_def_id ( did , tcx ) ;
842+ write ! ( f , "#{}.{}" , item_type . as_str ( ) , tcx . item_name ( did ) )
843+ }
844+ DefKind :: Field => {
847845 let parent_def_id = tcx. parent ( did) ;
848- let item_type =
849- ItemType :: from_def_kind ( def_kind, Some ( tcx. def_kind ( parent_def_id) ) ) ;
850- format ! ( "#{}.{}" , item_type. as_str( ) , tcx. item_name( did) )
851- } else {
852- String :: new ( )
853- } ;
846+ f. write_char ( '#' ) ?;
847+ if tcx. def_kind ( parent_def_id) == DefKind :: Variant {
848+ write ! ( f, "variant.{}.field" , tcx. item_name( parent_def_id) . as_str( ) ) ?;
849+ } else {
850+ f. write_str ( "structfield" ) ?;
851+ } ;
852+ write ! ( f, ".{}" , tcx. item_name( did) )
853+ }
854+ _ => Ok ( ( ) ) ,
855+ }
856+ } )
857+ }
854858
859+ pub ( crate ) fn print_anchor ( did : DefId , text : Symbol , cx : & Context < ' _ > ) -> impl Display {
860+ fmt:: from_fn ( move |f| {
861+ if let Ok ( HrefInfo { url, kind, rust_path } ) = href ( did, cx) {
855862 write ! (
856863 f,
857864 r#"<a class="{kind}" href="{url}{anchor}" title="{kind} {path}">{text}</a>"# ,
865+ anchor = fragment( did, cx. tcx( ) ) ,
858866 path = join_path_syms( rust_path) ,
859867 text = EscapeBodyText ( text. as_str( ) ) ,
860868 )
0 commit comments