Skip to content

Commit

Permalink
std: Create separate docs for the primitives
Browse files Browse the repository at this point in the history
Having the primitive and module docs derived from the same source
causes problems, primarily that they can't contain hyperlinks
cross-referencing each other.

This crates dedicated private modules in `std` to document the
primitive types, then for all primitives that have a corresponding
module, puts hyperlinks in moth the primitive docs and the module docs
cross-linking each other.

This should help clear up confusion when readers find themselves on
the wrong page.
  • Loading branch information
brson committed Jul 20, 2015
1 parent 44dd247 commit 8497c42
Show file tree
Hide file tree
Showing 40 changed files with 461 additions and 327 deletions.
4 changes: 2 additions & 2 deletions src/libcollections/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

//! A dynamically-sized view into a contiguous sequence, `[T]`.
//!
//! The `slice` module contains useful code to help work with slice values.
//! Slices are a view into a block of memory represented as a pointer and a
//! length.
//!
Expand Down Expand Up @@ -78,7 +77,8 @@
//! iterators.
//! * Further methods that return iterators are `.split()`, `.splitn()`,
//! `.chunks()`, `.windows()` and more.
#![doc(primitive = "slice")]
//!
//! *[See also the slice primitive type](../primitive.slice.html).*
#![stable(feature = "rust1", since = "1.0.0")]

// Many of the usings in this module are only used in the test configuration.
Expand Down
36 changes: 2 additions & 34 deletions src/libcollections/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,41 +10,9 @@

//! Unicode string slices
//!
//! Rust's `str` type is one of the core primitive types of the language. `&str`
//! is the borrowed string type. This type of string can only be created from
//! other strings, unless it is a `&'static str` (see below). It is not possible
//! to move out of borrowed strings because they are owned elsewhere.
//!
//! # Examples
//!
//! Here's some code that uses a `&str`:
//!
//! ```
//! let s = "Hello, world.";
//! ```
//!
//! This `&str` is a `&'static str`, which is the type of string literals.
//! They're `'static` because literals are available for the entire lifetime of
//! the program.
//!
//! You can get a non-`'static` `&str` by taking a slice of a `String`:
//!
//! ```
//! let some_string = "Hello, world.".to_string();
//! let s = &some_string;
//! ```
//!
//! # Representation
//!
//! Rust's string type, `str`, is a sequence of Unicode scalar values encoded as
//! a stream of UTF-8 bytes. All [strings](../../reference.html#literals) are
//! guaranteed to be validly encoded UTF-8 sequences. Additionally, strings are
//! not null-terminated and can thus contain null bytes.
//!
//! The actual representation of `str`s have direct mappings to slices: `&str`
//! is the same as `&[u8]`.
//! *[See also the `str` primitive type](../primitive.str.html).*


#![doc(primitive = "str")]
#![stable(feature = "rust1", since = "1.0.0")]

// Many of the usings in this module are only used in the test configuration.
Expand Down
3 changes: 2 additions & 1 deletion src/libcore/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
//! Implementations of things like `Eq` for fixed-length arrays
//! up to a certain length. Eventually we should able to generalize
//! to all lengths.
//!
//! *[See also the array primitive type](../primitive.array.html).*

#![doc(primitive = "array")]
#![unstable(feature = "fixed_size_array",
reason = "traits and impls are better expressed through generic \
integer constants")]
Expand Down
1 change: 0 additions & 1 deletion src/libcore/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
//! For more details, see ::rustc_unicode::char (a.k.a. std::char)

#![allow(non_snake_case)]
#![doc(primitive = "char")]
#![stable(feature = "core_char", since = "1.2.0")]

use iter::Iterator;
Expand Down
4 changes: 0 additions & 4 deletions src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,6 @@ pub mod str;
pub mod hash;
pub mod fmt;

#[doc(primitive = "bool")]
mod bool {
}

// note: does not need to be public
mod tuple;

Expand Down
1 change: 0 additions & 1 deletion src/libcore/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

//! Operations and constants for 32-bits floats (`f32` type)

#![doc(primitive = "f32")]
// FIXME: MIN_VALUE and MAX_VALUE literals are parsed as -inf and inf #14353
#![allow(overflowing_literals)]

Expand Down
1 change: 0 additions & 1 deletion src/libcore/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

//! Operations and constants for 64-bits floats (`f64` type)

#![doc(primitive = "f64")]
// FIXME: MIN_VALUE and MAX_VALUE literals are parsed as -inf and inf #14353
#![allow(overflowing_literals)]

Expand Down
1 change: 0 additions & 1 deletion src/libcore/num/i16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@
//! Operations and constants for signed 16-bits integers (`i16` type)

#![stable(feature = "rust1", since = "1.0.0")]
#![doc(primitive = "i16")]

int_module! { i16, 16 }
1 change: 0 additions & 1 deletion src/libcore/num/i32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@
//! Operations and constants for signed 32-bits integers (`i32` type)

#![stable(feature = "rust1", since = "1.0.0")]
#![doc(primitive = "i32")]

int_module! { i32, 32 }
1 change: 0 additions & 1 deletion src/libcore/num/i64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@
//! Operations and constants for signed 64-bits integers (`i64` type)

#![stable(feature = "rust1", since = "1.0.0")]
#![doc(primitive = "i64")]

int_module! { i64, 64 }
1 change: 0 additions & 1 deletion src/libcore/num/i8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@
//! Operations and constants for signed 8-bits integers (`i8` type)

#![stable(feature = "rust1", since = "1.0.0")]
#![doc(primitive = "i8")]

int_module! { i8, 8 }
1 change: 0 additions & 1 deletion src/libcore/num/isize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
//! Operations and constants for pointer-sized signed integers (`isize` type)

#![stable(feature = "rust1", since = "1.0.0")]
#![doc(primitive = "isize")]

#[cfg(target_pointer_width = "32")]
int_module! { isize, 32 }
Expand Down
1 change: 0 additions & 1 deletion src/libcore/num/u16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@
//! Operations and constants for unsigned 16-bits integers (`u16` type)

#![stable(feature = "rust1", since = "1.0.0")]
#![doc(primitive = "u16")]

uint_module! { u16, i16, 16 }
1 change: 0 additions & 1 deletion src/libcore/num/u32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@
//! Operations and constants for unsigned 32-bits integers (`u32` type)

#![stable(feature = "rust1", since = "1.0.0")]
#![doc(primitive = "u32")]

uint_module! { u32, i32, 32 }
1 change: 0 additions & 1 deletion src/libcore/num/u64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@
//! Operations and constants for unsigned 64-bits integer (`u64` type)

#![stable(feature = "rust1", since = "1.0.0")]
#![doc(primitive = "u64")]

uint_module! { u64, i64, 64 }
1 change: 0 additions & 1 deletion src/libcore/num/u8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@
//! Operations and constants for unsigned 8-bits integers (`u8` type)

#![stable(feature = "rust1", since = "1.0.0")]
#![doc(primitive = "u8")]

uint_module! { u8, i8, 8 }
1 change: 0 additions & 1 deletion src/libcore/num/usize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@
//! Operations and constants for pointer-sized unsigned integers (`usize` type)

#![stable(feature = "rust1", since = "1.0.0")]
#![doc(primitive = "usize")]

uint_module! { usize, isize, ::isize::BITS }
75 changes: 1 addition & 74 deletions src/libcore/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,82 +12,9 @@

//! Raw, unsafe pointers, `*const T`, and `*mut T`
//!
//! Working with raw pointers in Rust is uncommon,
//! typically limited to a few patterns.
//!
//! Use the `null` function to create null pointers, and the `is_null` method
//! of the `*const T` type to check for null. The `*const T` type also defines
//! the `offset` method, for pointer math.
//!
//! # Common ways to create raw pointers
//!
//! ## 1. Coerce a reference (`&T`) or mutable reference (`&mut T`).
//!
//! ```
//! let my_num: i32 = 10;
//! let my_num_ptr: *const i32 = &my_num;
//! let mut my_speed: i32 = 88;
//! let my_speed_ptr: *mut i32 = &mut my_speed;
//! ```
//!
//! To get a pointer to a boxed value, dereference the box:
//!
//! ```
//! let my_num: Box<i32> = Box::new(10);
//! let my_num_ptr: *const i32 = &*my_num;
//! let mut my_speed: Box<i32> = Box::new(88);
//! let my_speed_ptr: *mut i32 = &mut *my_speed;
//! ```
//!
//! This does not take ownership of the original allocation
//! and requires no resource management later,
//! but you must not use the pointer after its lifetime.
//!
//! ## 2. Consume a box (`Box<T>`).
//!
//! The `into_raw` function consumes a box and returns
//! the raw pointer. It doesn't destroy `T` or deallocate any memory.
//!
//! ```
//! # #![feature(box_raw)]
//! let my_speed: Box<i32> = Box::new(88);
//! let my_speed: *mut i32 = Box::into_raw(my_speed);
//!
//! // By taking ownership of the original `Box<T>` though
//! // we are obligated to put it together later to be destroyed.
//! unsafe {
//! drop(Box::from_raw(my_speed));
//! }
//! ```
//!
//! Note that here the call to `drop` is for clarity - it indicates
//! that we are done with the given value and it should be destroyed.
//!
//! ## 3. Get it from C.
//!
//! ```
//! # #![feature(libc)]
//! extern crate libc;
//!
//! use std::mem;
//!
//! fn main() {
//! unsafe {
//! let my_num: *mut i32 = libc::malloc(mem::size_of::<i32>() as libc::size_t) as *mut i32;
//! if my_num.is_null() {
//! panic!("failed to allocate memory");
//! }
//! libc::free(my_num as *mut libc::c_void);
//! }
//! }
//! ```
//!
//! Usually you wouldn't literally use `malloc` and `free` from Rust,
//! but C APIs hand out a lot of pointers generally, so are a common source
//! of raw pointers in Rust.
//! *[See also the pointer primitive types](../primitive.pointer.html).*

#![stable(feature = "rust1", since = "1.0.0")]
#![doc(primitive = "pointer")]

use mem;
use clone::Clone;
Expand Down
1 change: 0 additions & 1 deletion src/libcore/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
//! For more details `std::slice`.

#![stable(feature = "rust1", since = "1.0.0")]
#![doc(primitive = "slice")]

// How this module is organized.
//
Expand Down
1 change: 0 additions & 1 deletion src/libcore/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
//!
//! For more details, see std::str

#![doc(primitive = "str")]
#![stable(feature = "rust1", since = "1.0.0")]

use self::pattern::Pattern;
Expand Down
1 change: 0 additions & 1 deletion src/libcore/tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
//! * `Default`

#![stable(feature = "rust1", since = "1.0.0")]
#![doc(primitive = "tuple")]

use clone::Clone;
use cmp::*;
Expand Down
9 changes: 5 additions & 4 deletions src/librustc_unicode/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,20 @@
//! implementation for the primitive `char` type, in order to allow
//! basic character manipulation.
//!
//! A `char` actually represents a
//! *[Unicode Scalar
//! Value](http://www.unicode.org/glossary/#unicode_scalar_value)*, as it can
//! A `char` represents a
//! *[Unicode scalar
//! value](http://www.unicode.org/glossary/#unicode_scalar_value)*, as it can
//! contain any Unicode code point except high-surrogate and low-surrogate code
//! points.
//!
//! As such, only values in the ranges \[0x0,0xD7FF\] and \[0xE000,0x10FFFF\]
//! (inclusive) are allowed. A `char` can always be safely cast to a `u32`;
//! however the converse is not always true due to the above range limits
//! and, as such, should be performed via the `from_u32` function.
//!
//! *[See also the `char` primitive type](../primitive.char.html).*

#![stable(feature = "rust1", since = "1.0.0")]
#![doc(primitive = "char")]

use core::char::CharExt as C;
use core::option::Option::{self, Some, None};
Expand Down
55 changes: 0 additions & 55 deletions src/libstd/array.rs

This file was deleted.

14 changes: 0 additions & 14 deletions src/libstd/bool.rs

This file was deleted.

10 changes: 4 additions & 6 deletions src/libstd/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,12 +415,10 @@ pub mod __rand {
pub use rand::{thread_rng, ThreadRng, Rng};
}

// Modules that exist purely to document + host impl docs for primitive types

mod array;
mod bool;
mod unit;
mod tuple;
// Include a private number of modules that exist soley to provide the
// rustdoc documentation for primitive types. Using `include!` because
// rustdoc only looks for these modules at the crate level.
include!("primitive_docs.rs");

// A curious inner-module that's not exported that contains the binding
// 'std' so that macro-expanded references to std::error and such
Expand Down
Loading

0 comments on commit 8497c42

Please sign in to comment.