@@ -847,7 +847,7 @@ fn resolved_path<'cx>(
847
847
fn primitive_link(
848
848
f: &mut fmt::Formatter<'_>,
849
849
prim: clean::PrimitiveType,
850
- name: &str ,
850
+ name: fmt::Arguments<'_> ,
851
851
cx: &Context<'_>,
852
852
) -> fmt::Result {
853
853
primitive_link_fragment(f, prim, name, "", cx)
@@ -856,7 +856,7 @@ fn primitive_link(
856
856
fn primitive_link_fragment(
857
857
f: &mut fmt::Formatter<'_>,
858
858
prim: clean::PrimitiveType,
859
- name: &str ,
859
+ name: fmt::Arguments<'_> ,
860
860
fragment: &str,
861
861
cx: &Context<'_>,
862
862
) -> fmt::Result {
@@ -907,7 +907,7 @@ fn primitive_link_fragment(
907
907
None => {}
908
908
}
909
909
}
910
- f.write_str( name)?;
910
+ std::fmt::Display::fmt(& name, f )?;
911
911
if needs_termination {
912
912
write!(f, "</a>")?;
913
913
}
@@ -977,9 +977,11 @@ fn fmt_type<'cx>(
977
977
}
978
978
clean::Infer => write!(f, "_"),
979
979
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)
981
984
}
982
- clean::Primitive(prim) => primitive_link(f, prim, prim.as_sym().as_str(), cx),
983
985
clean::BareFunction(ref decl) => {
984
986
if f.alternate() {
985
987
write!(
@@ -998,16 +1000,16 @@ fn fmt_type<'cx>(
998
1000
decl.unsafety.print_with_space(),
999
1001
print_abi_with_space(decl.abi)
1000
1002
)?;
1001
- primitive_link(f, PrimitiveType::Fn, "fn", cx)?;
1003
+ primitive_link(f, PrimitiveType::Fn, format_args!( "fn") , cx)?;
1002
1004
write!(f, "{}", decl.decl.print(cx))
1003
1005
}
1004
1006
}
1005
1007
clean::Tuple(ref typs) => {
1006
1008
match &typs[..] {
1007
- &[] => primitive_link(f, PrimitiveType::Unit, "()", cx),
1009
+ &[] => primitive_link(f, PrimitiveType::Unit, format_args!( "()") , cx),
1008
1010
[one] => {
1009
1011
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)
1011
1013
} else {
1012
1014
write!(f, "(")?;
1013
1015
// Carry `f.alternate()` into this display w/o branching manually.
@@ -1028,7 +1030,10 @@ fn fmt_type<'cx>(
1028
1030
primitive_link(
1029
1031
f,
1030
1032
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
+ ),
1032
1037
cx,
1033
1038
)
1034
1039
} else {
@@ -1047,7 +1052,7 @@ fn fmt_type<'cx>(
1047
1052
}
1048
1053
clean::Slice(ref t) => match **t {
1049
1054
clean::Generic(name) => {
1050
- primitive_link(f, PrimitiveType::Slice, &format !("[{name}]"), cx)
1055
+ primitive_link(f, PrimitiveType::Slice, format_args !("[{name}]"), cx)
1051
1056
}
1052
1057
_ => {
1053
1058
write!(f, "[")?;
@@ -1059,7 +1064,7 @@ fn fmt_type<'cx>(
1059
1064
clean::Generic(name) if !f.alternate() => primitive_link(
1060
1065
f,
1061
1066
PrimitiveType::Array,
1062
- &format !("[{name}; {n}]", n = Escape(n)),
1067
+ format_args !("[{name}; {n}]", n = Escape(n)),
1063
1068
cx,
1064
1069
),
1065
1070
_ => {
@@ -1069,7 +1074,12 @@ fn fmt_type<'cx>(
1069
1074
write!(f, "; {n}")?;
1070
1075
} else {
1071
1076
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
+ )?;
1073
1083
}
1074
1084
write!(f, "]")
1075
1085
}
@@ -1081,30 +1091,40 @@ fn fmt_type<'cx>(
1081
1091
};
1082
1092
1083
1093
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
+ )
1086
1102
} 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
+ }
1090
1110
} else {
1091
- primitive_link(f, clean::PrimitiveType::RawPointer, &format !("*{m} "), cx)?;
1111
+ primitive_link(f, clean::PrimitiveType::RawPointer, format_args !("*{m} "), cx)?;
1092
1112
fmt::Display::fmt(&t.print(cx), f)
1093
1113
}
1094
1114
}
1095
1115
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
+ }) ;
1100
1120
let m = mutability.print_with_space();
1101
1121
let amp = if f.alternate() { "&" } else { "&" };
1102
1122
1103
1123
if let clean::Generic(name) = **ty {
1104
1124
return primitive_link(
1105
1125
f,
1106
1126
PrimitiveType::Reference,
1107
- &format !("{amp}{lt}{m}{name}"),
1127
+ format_args !("{amp}{lt}{m}{name}"),
1108
1128
cx,
1109
1129
);
1110
1130
}
@@ -1254,7 +1274,7 @@ impl clean::Impl {
1254
1274
{
1255
1275
// Hardcoded anchor library/core/src/primitive_docs.rs
1256
1276
// 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)?;
1258
1278
} else if let clean::BareFunction(bare_fn) = &self.for_ &&
1259
1279
let [clean::Argument { type_: clean::Type::Generic(name), .. }] = &bare_fn.decl.inputs.values[..] &&
1260
1280
(self.kind.is_fake_variadic() || self.kind.is_auto())
@@ -1281,7 +1301,7 @@ impl clean::Impl {
1281
1301
} else {
1282
1302
""
1283
1303
};
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)?;
1285
1305
// Write output.
1286
1306
if !bare_fn.decl.output.is_unit() {
1287
1307
write!(f, " -> ")?;
@@ -1665,7 +1685,12 @@ impl clean::ImportSource {
1665
1685
}
1666
1686
let name = self.path.last();
1667
1687
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
+ )?;
1669
1694
} else {
1670
1695
f.write_str(name.as_str())?;
1671
1696
}
0 commit comments