@@ -847,7 +847,7 @@ fn resolved_path<'cx>(
847847fn primitive_link (
848848 f : & mut fmt:: Formatter < ' _ > ,
849849 prim : clean:: PrimitiveType ,
850- name : & str ,
850+ name : fmt :: Arguments < ' _ > ,
851851 cx : & Context < ' _ > ,
852852) -> fmt:: Result {
853853 primitive_link_fragment ( f, prim, name, "" , cx)
@@ -856,7 +856,7 @@ fn primitive_link(
856856fn primitive_link_fragment (
857857 f : & mut fmt:: Formatter < ' _ > ,
858858 prim : clean:: PrimitiveType ,
859- name : & str ,
859+ name : fmt :: Arguments < ' _ > ,
860860 fragment : & str ,
861861 cx : & Context < ' _ > ,
862862) -> fmt:: Result {
@@ -907,7 +907,7 @@ fn primitive_link_fragment(
907907 None => { }
908908 }
909909 }
910- f . write_str ( name) ?;
910+ std :: fmt :: Display :: fmt ( & name, f ) ?;
911911 if needs_termination {
912912 write ! ( f, "</a>" ) ?;
913913 }
@@ -977,9 +977,11 @@ fn fmt_type<'cx>(
977977 }
978978 clean:: Infer => write ! ( f, "_" ) ,
979979 clean:: Primitive ( clean:: PrimitiveType :: Never ) => {
980- primitive_link ( f, PrimitiveType :: Never , "!" , cx)
980+ primitive_link ( f, PrimitiveType :: Never , format_args ! ( "!" ) , cx)
981+ }
982+ clean:: Primitive ( prim) => {
983+ primitive_link ( f, prim, format_args ! ( "{}" , prim. as_sym( ) . as_str( ) ) , cx)
981984 }
982- clean:: Primitive ( prim) => primitive_link ( f, prim, prim. as_sym ( ) . as_str ( ) , cx) ,
983985 clean:: BareFunction ( ref decl) => {
984986 if f. alternate ( ) {
985987 write ! (
@@ -998,16 +1000,16 @@ fn fmt_type<'cx>(
9981000 decl. unsafety. print_with_space( ) ,
9991001 print_abi_with_space( decl. abi)
10001002 ) ?;
1001- primitive_link ( f, PrimitiveType :: Fn , "fn" , cx) ?;
1003+ primitive_link ( f, PrimitiveType :: Fn , format_args ! ( "fn" ) , cx) ?;
10021004 write ! ( f, "{}" , decl. decl. print( cx) )
10031005 }
10041006 }
10051007 clean:: Tuple ( ref typs) => {
10061008 match & typs[ ..] {
1007- & [ ] => primitive_link ( f, PrimitiveType :: Unit , "()" , cx) ,
1009+ & [ ] => primitive_link ( f, PrimitiveType :: Unit , format_args ! ( "()" ) , cx) ,
10081010 [ one] => {
10091011 if let clean:: Generic ( name) = one {
1010- primitive_link ( f, PrimitiveType :: Tuple , & format ! ( "({name},)" ) , cx)
1012+ primitive_link ( f, PrimitiveType :: Tuple , format_args ! ( "({name},)" ) , cx)
10111013 } else {
10121014 write ! ( f, "(" ) ?;
10131015 // Carry `f.alternate()` into this display w/o branching manually.
@@ -1028,7 +1030,10 @@ fn fmt_type<'cx>(
10281030 primitive_link (
10291031 f,
10301032 PrimitiveType :: Tuple ,
1031- & format ! ( "({})" , generic_names. iter( ) . map( |s| s. as_str( ) ) . join( ", " ) ) ,
1033+ format_args ! (
1034+ "({})" ,
1035+ generic_names. iter( ) . map( |s| s. as_str( ) ) . join( ", " )
1036+ ) ,
10321037 cx,
10331038 )
10341039 } else {
@@ -1047,7 +1052,7 @@ fn fmt_type<'cx>(
10471052 }
10481053 clean:: Slice ( ref t) => match * * t {
10491054 clean:: Generic ( name) => {
1050- primitive_link ( f, PrimitiveType :: Slice , & format ! ( "[{name}]" ) , cx)
1055+ primitive_link ( f, PrimitiveType :: Slice , format_args ! ( "[{name}]" ) , cx)
10511056 }
10521057 _ => {
10531058 write ! ( f, "[" ) ?;
@@ -1059,7 +1064,7 @@ fn fmt_type<'cx>(
10591064 clean:: Generic ( name) if !f. alternate ( ) => primitive_link (
10601065 f,
10611066 PrimitiveType :: Array ,
1062- & format ! ( "[{name}; {n}]" , n = Escape ( n) ) ,
1067+ format_args ! ( "[{name}; {n}]" , n = Escape ( n) ) ,
10631068 cx,
10641069 ) ,
10651070 _ => {
@@ -1069,7 +1074,12 @@ fn fmt_type<'cx>(
10691074 write ! ( f, "; {n}" ) ?;
10701075 } else {
10711076 write ! ( f, "; " ) ?;
1072- primitive_link ( f, PrimitiveType :: Array , & format ! ( "{n}" , n = Escape ( n) ) , cx) ?;
1077+ primitive_link (
1078+ f,
1079+ PrimitiveType :: Array ,
1080+ format_args ! ( "{n}" , n = Escape ( n) ) ,
1081+ cx,
1082+ ) ?;
10731083 }
10741084 write ! ( f, "]" )
10751085 }
@@ -1081,30 +1091,40 @@ fn fmt_type<'cx>(
10811091 } ;
10821092
10831093 if matches ! ( * * t, clean:: Generic ( _) ) || t. is_assoc_ty ( ) {
1084- let text = if f. alternate ( ) {
1085- format ! ( "*{m} {ty:#}" , ty = t. print( cx) )
1094+ let ty = t. print ( cx) ;
1095+ if f. alternate ( ) {
1096+ primitive_link (
1097+ f,
1098+ clean:: PrimitiveType :: RawPointer ,
1099+ format_args ! ( "*{m} {ty:#}" ) ,
1100+ cx,
1101+ )
10861102 } else {
1087- format ! ( "*{m} {ty}" , ty = t. print( cx) )
1088- } ;
1089- primitive_link ( f, clean:: PrimitiveType :: RawPointer , & text, cx)
1103+ primitive_link (
1104+ f,
1105+ clean:: PrimitiveType :: RawPointer ,
1106+ format_args ! ( "*{m} {ty}" ) ,
1107+ cx,
1108+ )
1109+ }
10901110 } else {
1091- primitive_link ( f, clean:: PrimitiveType :: RawPointer , & format ! ( "*{m} " ) , cx) ?;
1111+ primitive_link ( f, clean:: PrimitiveType :: RawPointer , format_args ! ( "*{m} " ) , cx) ?;
10921112 fmt:: Display :: fmt ( & t. print ( cx) , f)
10931113 }
10941114 }
10951115 clean:: BorrowedRef { lifetime : ref l, mutability, type_ : ref ty } => {
1096- let lt = match l {
1097- Some ( l) => format ! ( "{} " , l. print( ) ) ,
1098- _ => String :: new ( ) ,
1099- } ;
1116+ let lt = display_fn ( |f| match l {
1117+ Some ( l) => write ! ( f , "{} " , l. print( ) ) ,
1118+ _ => Ok ( ( ) ) ,
1119+ } ) ;
11001120 let m = mutability. print_with_space ( ) ;
11011121 let amp = if f. alternate ( ) { "&" } else { "&" } ;
11021122
11031123 if let clean:: Generic ( name) = * * ty {
11041124 return primitive_link (
11051125 f,
11061126 PrimitiveType :: Reference ,
1107- & format ! ( "{amp}{lt}{m}{name}" ) ,
1127+ format_args ! ( "{amp}{lt}{m}{name}" ) ,
11081128 cx,
11091129 ) ;
11101130 }
@@ -1254,7 +1274,7 @@ impl clean::Impl {
12541274 {
12551275 // Hardcoded anchor library/core/src/primitive_docs.rs
12561276 // Link should match `# Trait implementations`
1257- primitive_link_fragment ( f, PrimitiveType :: Tuple , & format ! ( "({name}₁, {name}₂, …, {name}ₙ)" ) , "#trait-implementations-1" , cx) ?;
1277+ primitive_link_fragment ( f, PrimitiveType :: Tuple , format_args ! ( "({name}₁, {name}₂, …, {name}ₙ)" ) , "#trait-implementations-1" , cx) ?;
12581278 } else if let clean:: BareFunction ( bare_fn) = & self . for_ &&
12591279 let [ clean:: Argument { type_ : clean:: Type :: Generic ( name) , .. } ] = & bare_fn. decl . inputs . values [ ..] &&
12601280 ( self . kind . is_fake_variadic ( ) || self . kind . is_auto ( ) )
@@ -1281,7 +1301,7 @@ impl clean::Impl {
12811301 } else {
12821302 ""
12831303 } ;
1284- primitive_link_fragment ( f, PrimitiveType :: Tuple , & format ! ( "fn ({name}₁, {name}₂, …, {name}ₙ{ellipsis})" ) , "#trait-implementations-1" , cx) ?;
1304+ primitive_link_fragment ( f, PrimitiveType :: Tuple , format_args ! ( "fn ({name}₁, {name}₂, …, {name}ₙ{ellipsis})" ) , "#trait-implementations-1" , cx) ?;
12851305 // Write output.
12861306 if !bare_fn. decl . output . is_unit ( ) {
12871307 write ! ( f, " -> " ) ?;
@@ -1665,7 +1685,12 @@ impl clean::ImportSource {
16651685 }
16661686 let name = self . path . last ( ) ;
16671687 if let hir:: def:: Res :: PrimTy ( p) = self . path . res {
1668- primitive_link ( f, PrimitiveType :: from ( p) , name. as_str ( ) , cx) ?;
1688+ primitive_link (
1689+ f,
1690+ PrimitiveType :: from ( p) ,
1691+ format_args ! ( "{}" , name. as_str( ) ) ,
1692+ cx,
1693+ ) ?;
16691694 } else {
16701695 f. write_str ( name. as_str ( ) ) ?;
16711696 }
0 commit comments