diff options
| author | bors <bors@rust-lang.org> | 2016-07-13 16:27:30 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-07-13 16:27:30 -0700 |
| commit | 3dbbe2f716a09246939ad371125617c5526fd3fd (patch) | |
| tree | bd9ab3524a8a84dd7252b1a8df3480ef92f242dc /src/librustdoc | |
| parent | db71987ee1198be60fef3e361ad1ce59a70cd7f7 (diff) | |
| parent | 9d33ce58b104f1f0e29a69b30c6b4353f1e28c52 (diff) | |
| download | rust-3dbbe2f716a09246939ad371125617c5526fd3fd.tar.gz rust-3dbbe2f716a09246939ad371125617c5526fd3fd.zip | |
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
Diffstat (limited to 'src/librustdoc')
| -rw-r--r-- | src/librustdoc/Cargo.toml | 1 | ||||
| -rw-r--r-- | src/librustdoc/clean/mod.rs | 21 | ||||
| -rw-r--r-- | src/librustdoc/lib.rs | 1 |
3 files changed, 21 insertions, 2 deletions
diff --git a/src/librustdoc/Cargo.toml b/src/librustdoc/Cargo.toml index cf87aabdfdb..a41d3b0253a 100644 --- a/src/librustdoc/Cargo.toml +++ b/src/librustdoc/Cargo.toml @@ -14,6 +14,7 @@ arena = { path = "../libarena" } rustc = { path = "../librustc" } rustc_back = { path = "../librustc_back" } rustc_const_eval = { path = "../librustc_const_eval" } +rustc_const_math = { path = "../librustc_const_math" } rustc_driver = { path = "../librustc_driver" } rustc_errors = { path = "../librustc_errors" } rustc_lint = { path = "../librustc_lint" } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 7da17b37491..0211b2c9bc7 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -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) diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 2015bb295ea..d0c4f126550 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -34,6 +34,7 @@ extern crate getopts; extern crate libc; extern crate rustc; extern crate rustc_const_eval; +extern crate rustc_const_math; extern crate rustc_trans; extern crate rustc_driver; extern crate rustc_resolve; |
