about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Howell <michael@notriddle.com>2022-11-05 16:55:40 -0700
committerMichael Howell <michael@notriddle.com>2022-11-05 16:55:40 -0700
commite410cd25b2fc8180cd16b908c331363f8f81c803 (patch)
tree26d92adeac1f7cadf81b7ea31ecdca5551e5a5b7
parenta69d43493a91b11eb5b840253825330e9320a56f (diff)
downloadrust-e410cd25b2fc8180cd16b908c331363f8f81c803.tar.gz
rust-e410cd25b2fc8180cd16b908c331363f8f81c803.zip
rustdoc: print usize with less string manipulation
-rw-r--r--src/librustdoc/clean/utils.rs18
1 files changed, 6 insertions, 12 deletions
diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs
index 4e1f39cf87b..e3df367774b 100644
--- a/src/librustdoc/clean/utils.rs
+++ b/src/librustdoc/clean/utils.rs
@@ -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(),
     }
 }