diff options
| author | Oliver Schneider <git-spam-no-reply9815368754983@oli-obk.de> | 2016-07-13 10:35:58 +0200 |
|---|---|---|
| committer | Oliver Schneider <git-spam-no-reply9815368754983@oli-obk.de> | 2016-07-13 10:35:58 +0200 |
| commit | 9d33ce58b104f1f0e29a69b30c6b4353f1e28c52 (patch) | |
| tree | ab3c5a70f0593207f7735e8dadb1e3f80781c2dd /src/librustdoc | |
| parent | b4e11c2af8fce4f72fc896bfb6215c446d593cda (diff) | |
| download | rust-9d33ce58b104f1f0e29a69b30c6b4353f1e28c52.tar.gz rust-9d33ce58b104f1f0e29a69b30c6b4353f1e28c52.zip | |
evaluate the array length of fixed size array types in rustdoc
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 7827459baa8..0e9edb4dda8 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; |
