Skip to content

Commit

Permalink
rustdoc: Rename Vector and FixedVector to Slice and Array
Browse files Browse the repository at this point in the history
Also store the array length as a usize rather than a String.

This is just a minor refactor.
  • Loading branch information
ollie27 committed Jun 1, 2017
1 parent afd4b81 commit a74338d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
19 changes: 8 additions & 11 deletions src/librustdoc/clean/mod.rs
Expand Up @@ -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>),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)) => {
Expand Down Expand Up @@ -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),
Expand Down
15 changes: 4 additions & 11 deletions src/librustdoc/html/format.rs
Expand Up @@ -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};

Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit a74338d

Please sign in to comment.