Skip to content

Commit 2df8830

Browse files
committed
rustdoc: Support for "array" primitive
Impls on `clean::Type::FixedVector` are now collected in the array primitive page instead of the slice primitive page. Also add a primitive docs for arrays to `std`.
1 parent b0aad7d commit 2df8830

File tree

6 files changed

+38
-10
lines changed

6 files changed

+38
-10
lines changed

src/libcore/array.rs

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
1515
#![unstable(feature = "core")] // not yet reviewed
1616

17+
#![doc(primitive = "array")]
18+
1719
use clone::Clone;
1820
use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering};
1921
use fmt;

src/librustdoc/clean/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1322,7 +1322,8 @@ pub enum Type {
13221322
/// For parameterized types, so the consumer of the JSON don't go
13231323
/// looking for types which don't exist anywhere.
13241324
Generic(String),
1325-
/// Primitives are just the fixed-size numeric types (plus int/uint/float), and char.
1325+
/// Primitives are the fixed-size numeric types (plus int/uint/float), char,
1326+
/// arrays, slices, and tuples.
13261327
Primitive(PrimitiveType),
13271328
/// extern "ABI" fn
13281329
BareFunction(Box<BareFunctionDecl>),
@@ -1362,6 +1363,7 @@ pub enum PrimitiveType {
13621363
Bool,
13631364
Str,
13641365
Slice,
1366+
Array,
13651367
PrimitiveTuple,
13661368
}
13671369

@@ -1396,6 +1398,7 @@ impl PrimitiveType {
13961398
"str" => Some(Str),
13971399
"f32" => Some(F32),
13981400
"f64" => Some(F64),
1401+
"array" => Some(Array),
13991402
"slice" => Some(Slice),
14001403
"tuple" => Some(PrimitiveTuple),
14011404
_ => None,
@@ -1440,6 +1443,7 @@ impl PrimitiveType {
14401443
Str => "str",
14411444
Bool => "bool",
14421445
Char => "char",
1446+
Array => "array",
14431447
Slice => "slice",
14441448
PrimitiveTuple => "tuple",
14451449
}

src/librustdoc/html/format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ impl fmt::Display for clean::Type {
486486
primitive_link(f, clean::Slice, &format!("[{}]", **t))
487487
}
488488
clean::FixedVector(ref t, ref s) => {
489-
primitive_link(f, clean::Slice,
489+
primitive_link(f, clean::PrimitiveType::Array,
490490
&format!("[{}; {}]", **t, *s))
491491
}
492492
clean::Bottom => f.write_str("!"),

src/librustdoc/html/render.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,8 @@ impl DocFolder for Cache {
10261026
match item {
10271027
clean::Item{ attrs, inner: clean::ImplItem(i), .. } => {
10281028
use clean::{Primitive, Vector, ResolvedPath, BorrowedRef};
1029-
use clean::{FixedVector, Slice, Tuple, PrimitiveTuple};
1029+
use clean::PrimitiveType::{Array, Slice, PrimitiveTuple};
1030+
use clean::{FixedVector, Tuple};
10301031

10311032
// extract relevant documentation for this impl
10321033
let dox = match attrs.into_iter().find(|a| {
@@ -1056,12 +1057,16 @@ impl DocFolder for Cache {
10561057
Some(ast_util::local_def(p.to_node_id()))
10571058
}
10581059

1059-
// In a DST world, we may only need
1060-
// Vector/FixedVector, but for now we also pick up
1061-
// borrowed references
1062-
Vector(..) | FixedVector(..) |
1063-
BorrowedRef{ type_: box Vector(..), .. } |
1064-
BorrowedRef{ type_: box FixedVector(..), .. } =>
1060+
FixedVector(..) |
1061+
BorrowedRef { type_: box FixedVector(..), .. } =>
1062+
{
1063+
Some(ast_util::local_def(Array.to_node_id()))
1064+
}
1065+
1066+
// In a DST world, we may only need Vector, but for now we
1067+
// also pick up borrowed references
1068+
Vector(..) |
1069+
BorrowedRef{ type_: box Vector(..), .. } =>
10651070
{
10661071
Some(ast_util::local_def(Slice.to_node_id()))
10671072
}

src/libstd/array.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
//! The fixed-size array type (`[T; n]`).
12+
13+
#![doc(primitive = "array")]

src/libstd/lib.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ pub mod prelude;
212212

213213
/* Primitive types */
214214

215+
// NB: slice and str are primitive types too, but their module docs + primitive doc pages
216+
// are inlined from the public re-exports of core_collections::{slice, str} above.
217+
215218
#[path = "num/float_macros.rs"]
216219
#[macro_use]
217220
mod float_macros;
@@ -285,8 +288,9 @@ pub mod sync;
285288
pub mod rt;
286289
mod panicking;
287290

288-
// Documentation for primitive types
291+
// Modules that exist purely to document + host impl docs for primitive types
289292

293+
mod array;
290294
mod bool;
291295
mod unit;
292296
mod tuple;

0 commit comments

Comments
 (0)