Skip to content

Commit

Permalink
rustdoc: print usize with less string manipulation
Browse files Browse the repository at this point in the history
  • Loading branch information
notriddle committed Nov 5, 2022
1 parent a69d434 commit e410cd2
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions src/librustdoc/clean/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,19 +242,13 @@ pub(crate) fn print_const(cx: &DocContext<'_>, n: ty::Const<'_>) -> String {

s
}
_ => {
let mut s = n.to_string();
// array lengths are obviously usize
if s.ends_with("_usize") {
let n = s.len() - "_usize".len();
s.truncate(n);
if s.ends_with(": ") {
let n = s.len() - ": ".len();
s.truncate(n);
}
}
s
// array lengths are obviously usize
ty::ConstKind::Value(ty::ValTree::Leaf(scalar))
if *n.ty().kind() == ty::Uint(ty::UintTy::Usize) =>
{
scalar.to_string()
}
_ => n.to_string(),
}
}

Expand Down

0 comments on commit e410cd2

Please sign in to comment.