Skip to content

Commit e410cd2

Browse files
committed
rustdoc: print usize with less string manipulation
1 parent a69d434 commit e410cd2

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

src/librustdoc/clean/utils.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -242,19 +242,13 @@ pub(crate) fn print_const(cx: &DocContext<'_>, n: ty::Const<'_>) -> String {
242242

243243
s
244244
}
245-
_ => {
246-
let mut s = n.to_string();
247-
// array lengths are obviously usize
248-
if s.ends_with("_usize") {
249-
let n = s.len() - "_usize".len();
250-
s.truncate(n);
251-
if s.ends_with(": ") {
252-
let n = s.len() - ": ".len();
253-
s.truncate(n);
254-
}
255-
}
256-
s
245+
// array lengths are obviously usize
246+
ty::ConstKind::Value(ty::ValTree::Leaf(scalar))
247+
if *n.ty().kind() == ty::Uint(ty::UintTy::Usize) =>
248+
{
249+
scalar.to_string()
257250
}
251+
_ => n.to_string(),
258252
}
259253
}
260254

0 commit comments

Comments
 (0)