rollup merge of #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.
This commit is contained in:
Alex Crichton 2014-12-21 00:04:08 -08:00
commit fc40812b0f
9 changed files with 86 additions and 37 deletions

View File

@ -107,7 +107,6 @@ pub mod default;
pub mod any; pub mod any;
pub mod atomic; pub mod atomic;
pub mod bool;
pub mod borrow; pub mod borrow;
pub mod cell; pub mod cell;
pub mod char; pub mod char;
@ -120,15 +119,11 @@ pub mod result;
pub mod simd; pub mod simd;
pub mod slice; pub mod slice;
pub mod str; pub mod str;
pub mod tuple;
pub mod hash; pub mod hash;
// FIXME #15320: primitive documentation needs top-level modules, this
// should be `core::tuple::unit`.
#[path = "tuple/unit.rs"]
pub mod unit;
pub mod fmt; pub mod fmt;
// note: does not need to be public // note: does not need to be public
mod tuple;
mod array; mod array;
#[doc(hidden)] #[doc(hidden)]

View File

@ -62,12 +62,10 @@
//! assert_eq!(d, (0u32, 0.0f32)); //! assert_eq!(d, (0u32, 0.0f32));
//! ``` //! ```
#![doc(primitive = "tuple")]
#![stable] #![stable]
#[unstable = "this is just a documentation module and should not be part \ #[unstable = "this is just a documentation module and should not be part \
of the public api"] of the public api"]
pub use unit;
use clone::Clone; use clone::Clone;
use cmp::*; use cmp::*;

View File

@ -163,33 +163,24 @@ impl<'a, 'tcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx> {
}; };
let mut tmp = Vec::new(); let mut tmp = Vec::new();
for child in m.items.iter_mut() { for child in m.items.iter_mut() {
let inner = match child.inner { match child.inner {
ModuleItem(ref mut m) => m, ModuleItem(..) => {}
_ => continue, _ => continue,
}; }
let prim = match PrimitiveType::find(child.attrs.as_slice()) { let prim = match PrimitiveType::find(child.attrs.as_slice()) {
Some(prim) => prim, Some(prim) => prim,
None => continue, None => continue,
}; };
primitives.push(prim); primitives.push(prim);
let mut i = Item { tmp.push(Item {
source: Span::empty(), source: Span::empty(),
name: Some(prim.to_url_str().to_string()), name: Some(prim.to_url_str().to_string()),
attrs: Vec::new(), attrs: child.attrs.clone(),
visibility: None, visibility: Some(ast::Public),
stability: None, stability: None,
def_id: ast_util::local_def(prim.to_node_id()), def_id: ast_util::local_def(prim.to_node_id()),
inner: PrimitiveItem(prim), inner: PrimitiveItem(prim),
}; });
// Push one copy to get indexed for the whole crate, and push a
// another copy in the proper location which will actually get
// documented. The first copy will also serve as a redirect to
// the other copy.
tmp.push(i.clone());
i.visibility = Some(ast::Public);
i.attrs = child.attrs.clone();
inner.items.push(i);
} }
m.items.extend(tmp.into_iter()); m.items.extend(tmp.into_iter());
} }

View File

@ -11,6 +11,5 @@
//! The boolean type //! The boolean type
#![doc(primitive = "bool")] #![doc(primitive = "bool")]
#![unstable = "this module is purely for documentation and it will likely be \ #![stable]
removed from the public api"]

View File

@ -135,7 +135,6 @@ extern crate libc;
// NB: These reexports are in the order they should be listed in rustdoc // NB: These reexports are in the order they should be listed in rustdoc
pub use core::any; pub use core::any;
pub use core::bool;
pub use core::borrow; pub use core::borrow;
pub use core::cell; pub use core::cell;
pub use core::clone; pub use core::clone;
@ -150,10 +149,6 @@ pub use core::mem;
pub use core::ptr; pub use core::ptr;
pub use core::raw; pub use core::raw;
pub use core::simd; pub use core::simd;
pub use core::tuple;
// FIXME #15320: primitive documentation needs top-level modules, this
// should be `std::tuple::unit`.
pub use core::unit;
pub use core::result; pub use core::result;
pub use core::option; pub use core::option;
@ -243,6 +238,12 @@ pub mod comm;
pub mod rt; pub mod rt;
mod failure; mod failure;
// Documentation for primitive types
mod bool;
mod unit;
mod tuple;
// A curious inner-module that's not exported that contains the binding // A curious inner-module that's not exported that contains the binding
// 'std' so that macro-expanded references to std::error and such // 'std' so that macro-expanded references to std::error and such
// can be resolved within libstd. // can be resolved within libstd.

View File

@ -81,9 +81,9 @@
#[doc(no_inline)] pub use io::{Buffer, Writer, Reader, Seek, BufferPrelude}; #[doc(no_inline)] pub use io::{Buffer, Writer, Reader, Seek, BufferPrelude};
#[doc(no_inline)] pub use str::{Str, StrVector, StrPrelude}; #[doc(no_inline)] pub use str::{Str, StrVector, StrPrelude};
#[doc(no_inline)] pub use str::{StrAllocating, UnicodeStrPrelude}; #[doc(no_inline)] pub use str::{StrAllocating, UnicodeStrPrelude};
#[doc(no_inline)] pub use tuple::{Tuple1, Tuple2, Tuple3, Tuple4}; #[doc(no_inline)] pub use core::prelude::{Tuple1, Tuple2, Tuple3, Tuple4};
#[doc(no_inline)] pub use tuple::{Tuple5, Tuple6, Tuple7, Tuple8}; #[doc(no_inline)] pub use core::prelude::{Tuple5, Tuple6, Tuple7, Tuple8};
#[doc(no_inline)] pub use tuple::{Tuple9, Tuple10, Tuple11, Tuple12}; #[doc(no_inline)] pub use core::prelude::{Tuple9, Tuple10, Tuple11, Tuple12};
#[doc(no_inline)] pub use slice::AsSlice; #[doc(no_inline)] pub use slice::AsSlice;
#[doc(no_inline)] pub use slice::{VectorVector, PartialEqSliceExt}; #[doc(no_inline)] pub use slice::{VectorVector, PartialEqSliceExt};
#[doc(no_inline)] pub use slice::{CloneSliceExt, OrdSliceExt, SliceExt}; #[doc(no_inline)] pub use slice::{CloneSliceExt, OrdSliceExt, SliceExt};

66
src/libstd/tuple.rs Normal file
View File

@ -0,0 +1,66 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//! Operations on tuples
//!
//! To access a single element of a tuple one can use the following
//! methods:
//!
//! * `valN` - returns a value of _N_-th element
//! * `refN` - returns a reference to _N_-th element
//! * `mutN` - returns a mutable reference to _N_-th element
//!
//! Indexing starts from zero, so `val0` returns first value, `val1`
//! returns second value, and so on. In general, a tuple with _S_
//! elements provides aforementioned methods suffixed with numbers
//! from `0` to `S-1`. Traits which contain these methods are
//! implemented for tuples with up to 12 elements.
//!
//! If every type inside a tuple implements one of the following
//! traits, then a tuple itself also implements it.
//!
//! * `Clone`
//! * `PartialEq`
//! * `Eq`
//! * `PartialOrd`
//! * `Ord`
//! * `Default`
//!
//! # Examples
//!
//! Using methods:
//!
//! ```
//! #[allow(deprecated)]
//! # fn main() {
//! let pair = ("pi", 3.14f64);
//! assert_eq!(pair.val0(), "pi");
//! assert_eq!(pair.val1(), 3.14f64);
//! # }
//! ```
//!
//! Using traits implemented for tuples:
//!
//! ```
//! use std::default::Default;
//!
//! let a = (1i, 2i);
//! let b = (3i, 4i);
//! assert!(a != b);
//!
//! let c = b.clone();
//! assert!(b == c);
//!
//! let d : (u32, f32) = Default::default();
//! assert_eq!(d, (0u32, 0.0f32));
//! ```
#![doc(primitive = "tuple")]
#![stable]

View File

@ -9,8 +9,7 @@
// except according to those terms. // except according to those terms.
#![doc(primitive = "unit")] #![doc(primitive = "unit")]
#![unstable = "this module is purely for documentation and it will likely be \ #![stable]
removed from the public api"]
//! The `()` type, sometimes called "unit" or "nil". //! The `()` type, sometimes called "unit" or "nil".
//! //!

View File

@ -11,5 +11,5 @@
pub extern crate core; //~ ERROR: `pub` visibility is not allowed pub extern crate core; //~ ERROR: `pub` visibility is not allowed
fn main() { fn main() {
pub use std::bool; //~ ERROR: imports in functions are never reachable pub use std::uint; //~ ERROR: imports in functions are never reachable
} }