]> git.lizzy.rs Git - rust.git/blobdiff - src/librustdoc/clean/mod.rs
Auto merge of #34684 - oli-obk:eval_rustdoc_array_len, r=alexcrichton
[rust.git] / src / librustdoc / clean / mod.rs
index 7da17b3749104ecff45962ead1407cb111076556..0211b2c9bc7ba5176c06cfd9d433bc0143264276 100644 (file)
@@ -1624,8 +1624,25 @@ fn clean(&self, cx: &DocContext) -> Type {
                 BorrowedRef {lifetime: l.clean(cx), mutability: m.mutbl.clean(cx),
                              type_: box m.ty.clean(cx)},
             TyVec(ref ty) => Vector(box ty.clean(cx)),
-            TyFixedLengthVec(ref ty, ref e) =>
-                FixedVector(box ty.clean(cx), pprust::expr_to_string(e)),
+            TyFixedLengthVec(ref ty, ref e) => {
+                let n = if let Some(tcx) = cx.tcx_opt() {
+                    use rustc_const_math::{ConstInt, ConstUsize};
+                    use rustc_const_eval::eval_const_expr;
+                    use rustc::middle::const_val::ConstVal;
+                    match eval_const_expr(tcx, e) {
+                        ConstVal::Integral(ConstInt::Usize(u)) => match u {
+                            ConstUsize::Us16(u) => u.to_string(),
+                            ConstUsize::Us32(u) => u.to_string(),
+                            ConstUsize::Us64(u) => u.to_string(),
+                        },
+                        // after type checking this can't fail
+                        _ => unreachable!(),
+                    }
+                } else {
+                    pprust::expr_to_string(e)
+                };
+                FixedVector(box ty.clean(cx), n)
+            },
             TyTup(ref tys) => Tuple(tys.clean(cx)),
             TyPath(None, ref p) => {
                 resolve_type(cx, p.clean(cx), self.id)