1
Fork 0

Auto merge of #34684 - oli-obk:eval_rustdoc_array_len, r=alexcrichton

evaluate the array length of fixed size array types in rustdoc

mitgates #34579

to fix it we'd need an expression simplifier.

r? @steveklabnik

cc @Osspial
This commit is contained in:
bors 2016-07-13 16:27:30 -07:00 committed by GitHub
commit 3dbbe2f716
5 changed files with 24 additions and 4 deletions

View file

@ -1624,8 +1624,25 @@ impl Clean<Type> for hir::Ty {
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)