Skip to content

Commit fc40812

Browse files
committed
rollup merge of rust-lang#20006: alexcrichton/no-more-empty-modules
This commit modifies rustdoc to not require these empty modules to be public in the standard library. The modules still remain as a location to attach documentation to, but the modules themselves are now private (don't have to commit to an API). The documentation for the standard library now shows all of the primitive types on the main index page.
2 parents 4ae3107 + 1b42e89 commit fc40812

File tree

9 files changed

+86
-37
lines changed

9 files changed

+86
-37
lines changed

src/libcore/lib.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ pub mod default;
107107

108108
pub mod any;
109109
pub mod atomic;
110-
pub mod bool;
111110
pub mod borrow;
112111
pub mod cell;
113112
pub mod char;
@@ -120,15 +119,11 @@ pub mod result;
120119
pub mod simd;
121120
pub mod slice;
122121
pub mod str;
123-
pub mod tuple;
124122
pub mod hash;
125-
// FIXME #15320: primitive documentation needs top-level modules, this
126-
// should be `core::tuple::unit`.
127-
#[path = "tuple/unit.rs"]
128-
pub mod unit;
129123
pub mod fmt;
130124

131125
// note: does not need to be public
126+
mod tuple;
132127
mod array;
133128

134129
#[doc(hidden)]

src/libcore/tuple/mod.rs renamed to src/libcore/tuple.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,10 @@
6262
//! assert_eq!(d, (0u32, 0.0f32));
6363
//! ```
6464
65-
#![doc(primitive = "tuple")]
6665
#![stable]
6766

6867
#[unstable = "this is just a documentation module and should not be part \
6968
of the public api"]
70-
pub use unit;
7169

7270
use clone::Clone;
7371
use cmp::*;

src/librustdoc/clean/mod.rs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -163,33 +163,24 @@ impl<'a, 'tcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx> {
163163
};
164164
let mut tmp = Vec::new();
165165
for child in m.items.iter_mut() {
166-
let inner = match child.inner {
167-
ModuleItem(ref mut m) => m,
166+
match child.inner {
167+
ModuleItem(..) => {}
168168
_ => continue,
169-
};
169+
}
170170
let prim = match PrimitiveType::find(child.attrs.as_slice()) {
171171
Some(prim) => prim,
172172
None => continue,
173173
};
174174
primitives.push(prim);
175-
let mut i = Item {
175+
tmp.push(Item {
176176
source: Span::empty(),
177177
name: Some(prim.to_url_str().to_string()),
178-
attrs: Vec::new(),
179-
visibility: None,
178+
attrs: child.attrs.clone(),
179+
visibility: Some(ast::Public),
180180
stability: None,
181181
def_id: ast_util::local_def(prim.to_node_id()),
182182
inner: PrimitiveItem(prim),
183-
};
184-
// Push one copy to get indexed for the whole crate, and push a
185-
// another copy in the proper location which will actually get
186-
// documented. The first copy will also serve as a redirect to
187-
// the other copy.
188-
tmp.push(i.clone());
189-
i.visibility = Some(ast::Public);
190-
i.attrs = child.attrs.clone();
191-
inner.items.push(i);
192-
183+
});
193184
}
194185
m.items.extend(tmp.into_iter());
195186
}

src/libcore/bool.rs renamed to src/libstd/bool.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,5 @@
1111
//! The boolean type
1212
1313
#![doc(primitive = "bool")]
14-
#![unstable = "this module is purely for documentation and it will likely be \
15-
removed from the public api"]
14+
#![stable]
1615

src/libstd/lib.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ extern crate libc;
135135
// NB: These reexports are in the order they should be listed in rustdoc
136136

137137
pub use core::any;
138-
pub use core::bool;
139138
pub use core::borrow;
140139
pub use core::cell;
141140
pub use core::clone;
@@ -150,10 +149,6 @@ pub use core::mem;
150149
pub use core::ptr;
151150
pub use core::raw;
152151
pub use core::simd;
153-
pub use core::tuple;
154-
// FIXME #15320: primitive documentation needs top-level modules, this
155-
// should be `std::tuple::unit`.
156-
pub use core::unit;
157152
pub use core::result;
158153
pub use core::option;
159154

@@ -243,6 +238,12 @@ pub mod comm;
243238
pub mod rt;
244239
mod failure;
245240

241+
// Documentation for primitive types
242+
243+
mod bool;
244+
mod unit;
245+
mod tuple;
246+
246247
// A curious inner-module that's not exported that contains the binding
247248
// 'std' so that macro-expanded references to std::error and such
248249
// can be resolved within libstd.

src/libstd/prelude.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@
8181
#[doc(no_inline)] pub use io::{Buffer, Writer, Reader, Seek, BufferPrelude};
8282
#[doc(no_inline)] pub use str::{Str, StrVector, StrPrelude};
8383
#[doc(no_inline)] pub use str::{StrAllocating, UnicodeStrPrelude};
84-
#[doc(no_inline)] pub use tuple::{Tuple1, Tuple2, Tuple3, Tuple4};
85-
#[doc(no_inline)] pub use tuple::{Tuple5, Tuple6, Tuple7, Tuple8};
86-
#[doc(no_inline)] pub use tuple::{Tuple9, Tuple10, Tuple11, Tuple12};
84+
#[doc(no_inline)] pub use core::prelude::{Tuple1, Tuple2, Tuple3, Tuple4};
85+
#[doc(no_inline)] pub use core::prelude::{Tuple5, Tuple6, Tuple7, Tuple8};
86+
#[doc(no_inline)] pub use core::prelude::{Tuple9, Tuple10, Tuple11, Tuple12};
8787
#[doc(no_inline)] pub use slice::AsSlice;
8888
#[doc(no_inline)] pub use slice::{VectorVector, PartialEqSliceExt};
8989
#[doc(no_inline)] pub use slice::{CloneSliceExt, OrdSliceExt, SliceExt};

src/libstd/tuple.rs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// Copyright 2012 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+
//! Operations on tuples
12+
//!
13+
//! To access a single element of a tuple one can use the following
14+
//! methods:
15+
//!
16+
//! * `valN` - returns a value of _N_-th element
17+
//! * `refN` - returns a reference to _N_-th element
18+
//! * `mutN` - returns a mutable reference to _N_-th element
19+
//!
20+
//! Indexing starts from zero, so `val0` returns first value, `val1`
21+
//! returns second value, and so on. In general, a tuple with _S_
22+
//! elements provides aforementioned methods suffixed with numbers
23+
//! from `0` to `S-1`. Traits which contain these methods are
24+
//! implemented for tuples with up to 12 elements.
25+
//!
26+
//! If every type inside a tuple implements one of the following
27+
//! traits, then a tuple itself also implements it.
28+
//!
29+
//! * `Clone`
30+
//! * `PartialEq`
31+
//! * `Eq`
32+
//! * `PartialOrd`
33+
//! * `Ord`
34+
//! * `Default`
35+
//!
36+
//! # Examples
37+
//!
38+
//! Using methods:
39+
//!
40+
//! ```
41+
//! #[allow(deprecated)]
42+
//! # fn main() {
43+
//! let pair = ("pi", 3.14f64);
44+
//! assert_eq!(pair.val0(), "pi");
45+
//! assert_eq!(pair.val1(), 3.14f64);
46+
//! # }
47+
//! ```
48+
//!
49+
//! Using traits implemented for tuples:
50+
//!
51+
//! ```
52+
//! use std::default::Default;
53+
//!
54+
//! let a = (1i, 2i);
55+
//! let b = (3i, 4i);
56+
//! assert!(a != b);
57+
//!
58+
//! let c = b.clone();
59+
//! assert!(b == c);
60+
//!
61+
//! let d : (u32, f32) = Default::default();
62+
//! assert_eq!(d, (0u32, 0.0f32));
63+
//! ```
64+
65+
#![doc(primitive = "tuple")]
66+
#![stable]

src/libcore/tuple/unit.rs renamed to src/libstd/unit.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
// except according to those terms.
1010

1111
#![doc(primitive = "unit")]
12-
#![unstable = "this module is purely for documentation and it will likely be \
13-
removed from the public api"]
12+
#![stable]
1413

1514
//! The `()` type, sometimes called "unit" or "nil".
1615
//!

src/test/compile-fail/issue-9957.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
pub extern crate core; //~ ERROR: `pub` visibility is not allowed
1212

1313
fn main() {
14-
pub use std::bool; //~ ERROR: imports in functions are never reachable
14+
pub use std::uint; //~ ERROR: imports in functions are never reachable
1515
}

0 commit comments

Comments
 (0)