Rollup merge of #42360 - ollie27:rustdoc_vector_rename, r=GuillaumeGomez

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.
This commit is contained in:
Mark Simulacrum 2017-06-02 09:10:47 -06:00 committed by GitHub
commit 7a2d4b30b6
2 changed files with 12 additions and 22 deletions

View File

@ -1506,8 +1506,8 @@ pub enum Type {
/// extern "ABI" fn
BareFunction(Box<BareFunctionDecl>),
Tuple(Vec<Type>),
Vector(Box<Type>),
FixedVector(Box<Type>, String),
Slice(Box<Type>),
Array(Box<Type>, usize),
Never,
Unique(Box<Type>),
RawPointer(Mutability, Box<Type>),
@ -1573,10 +1573,8 @@ impl Type {
pub fn primitive_type(&self) -> Option<PrimitiveType> {
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<Type> 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<Type> 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),

View File

@ -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() {