From a74338d60e962a61a7b336aea4439973b2861f7e Mon Sep 17 00:00:00 2001 From: Oliver Middleton Date: Wed, 31 May 2017 14:39:30 +0100 Subject: [PATCH] rustdoc: Rename `Vector` and `FixedVector` to `Slice` and `Array` Also store the array length as a usize rather than a String. This is just a minor refactor. --- src/librustdoc/clean/mod.rs | 19 ++++++++----------- src/librustdoc/html/format.rs | 15 ++++----------- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 9464ac83870d9..25e55ff36e7c6 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1506,8 +1506,8 @@ pub enum Type { /// extern "ABI" fn BareFunction(Box), Tuple(Vec), - Vector(Box), - FixedVector(Box, String), + Slice(Box), + Array(Box, usize), Never, Unique(Box), RawPointer(Mutability, Box), @@ -1573,10 +1573,8 @@ impl Type { pub fn primitive_type(&self) -> Option { match *self { Primitive(p) | BorrowedRef { type_: box Primitive(p), ..} => Some(p), - Vector(..) | BorrowedRef{ type_: box Vector(..), .. } => Some(PrimitiveType::Slice), - FixedVector(..) | BorrowedRef { type_: box FixedVector(..), .. } => { - Some(PrimitiveType::Array) - } + Slice(..) | BorrowedRef { type_: box Slice(..), .. } => Some(PrimitiveType::Slice), + Array(..) | BorrowedRef { type_: box Array(..), .. } => Some(PrimitiveType::Array), Tuple(..) => Some(PrimitiveType::Tuple), RawPointer(..) => Some(PrimitiveType::RawPointer), _ => None, @@ -1717,11 +1715,11 @@ impl Clean for hir::Ty { BorrowedRef {lifetime: lifetime, mutability: m.mutbl.clean(cx), type_: box m.ty.clean(cx)} } - TySlice(ref ty) => Vector(box ty.clean(cx)), + TySlice(ref ty) => Slice(box ty.clean(cx)), TyArray(ref ty, length) => { use rustc::middle::const_val::eval_length; let n = eval_length(cx.tcx, length, "array length").unwrap(); - FixedVector(box ty.clean(cx), n.to_string()) + Array(box ty.clean(cx), n) }, TyTup(ref tys) => Tuple(tys.clean(cx)), TyPath(hir::QPath::Resolved(None, ref path)) => { @@ -1832,9 +1830,8 @@ impl<'tcx> Clean for ty::Ty<'tcx> { ty::TyUint(uint_ty) => Primitive(uint_ty.into()), ty::TyFloat(float_ty) => Primitive(float_ty.into()), ty::TyStr => Primitive(PrimitiveType::Str), - ty::TySlice(ty) => Vector(box ty.clean(cx)), - ty::TyArray(ty, i) => FixedVector(box ty.clean(cx), - format!("{}", i)), + ty::TySlice(ty) => Slice(box ty.clean(cx)), + ty::TyArray(ty, n) => Array(box ty.clean(cx), n), ty::TyRawPtr(mt) => RawPointer(mt.mutbl.clean(cx), box mt.ty.clean(cx)), ty::TyRef(r, mt) => BorrowedRef { lifetime: r.clean(cx), diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 6111ea073dd19..86660c28f80ad 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -25,7 +25,6 @@ use rustc::hir; use clean::{self, PrimitiveType}; use core::DocAccessLevels; use html::item_type::ItemType; -use html::escape::Escape; use html::render; use html::render::{cache, CURRENT_LOCATION_KEY}; @@ -643,21 +642,15 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool) -> fmt: } } } - clean::Vector(ref t) => { + clean::Slice(ref t) => { primitive_link(f, PrimitiveType::Slice, "[")?; fmt::Display::fmt(t, f)?; primitive_link(f, PrimitiveType::Slice, "]") } - clean::FixedVector(ref t, ref s) => { + clean::Array(ref t, n) => { primitive_link(f, PrimitiveType::Array, "[")?; fmt::Display::fmt(t, f)?; - if f.alternate() { - primitive_link(f, PrimitiveType::Array, - &format!("; {}]", s)) - } else { - primitive_link(f, PrimitiveType::Array, - &format!("; {}]", Escape(s))) - } + primitive_link(f, PrimitiveType::Array, &format!("; {}]", n)) } clean::Never => f.write_str("!"), clean::RawPointer(m, ref t) => { @@ -685,7 +678,7 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter, use_absolute: bool) -> fmt: }; let m = MutableSpace(mutability); match **ty { - clean::Vector(ref bt) => { // BorrowedRef{ ... Vector(T) } is &[T] + clean::Slice(ref bt) => { // BorrowedRef{ ... Slice(T) } is &[T] match **bt { clean::Generic(_) => { if f.alternate() {