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:
commit
3dbbe2f716
5 changed files with 24 additions and 4 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue