@@ -833,26 +833,27 @@ fn print_higher_ranked_params_with_space(
833833 } )
834834}
835835
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) )
836+ pub ( crate ) fn fragment ( did : DefId , tcx : TyCtxt < ' _ > ) -> impl Display {
837+ fmt:: from_fn ( move |f| {
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 => {
845+ let parent_def_id = tcx. parent ( did) ;
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 ( ( ) ) ,
853855 }
854- _ => String :: new ( ) ,
855- }
856+ } )
856857}
857858
858859pub ( crate ) fn print_anchor ( did : DefId , text : Symbol , cx : & Context < ' _ > ) -> impl Display {
0 commit comments