Skip to content

Commit

Permalink
rustdoc: Create anchor pages for primitive types
Browse files Browse the repository at this point in the history
This commit adds support in rustdoc to recognize the `#[doc(primitive = "foo")]`
attribute. This attribute indicates that the current module is the "owner" of
the primitive type `foo`. For rustdoc, this means that the doc-comment for the
module is the doc-comment for the primitive type, plus a signal to all
downstream crates that hyperlinks for primitive types will be directed at the
crate containing the `#[doc]` directive.

Additionally, rustdoc will favor crates closest to the one being documented
which "implements the primitive type". For example, documentation of libcore
links to libcore for primitive types, but documentation for libstd and beyond
all links to libstd for primitive types.

This change involves no compiler modifications, it is purely a rustdoc change.
The landing pages for the primitive types primarily serve to show a list of
implemented traits for the primitive type itself.

The primitive types documented includes both strings and slices in a semi-ad-hoc
way, but in a way that should provide at least somewhat meaningful
documentation.

Closes rust-lang#14474
  • Loading branch information
alexcrichton committed May 30, 2014
1 parent 949bfbc commit f7af780
Show file tree
Hide file tree
Showing 37 changed files with 443 additions and 87 deletions.
2 changes: 2 additions & 0 deletions src/libcore/bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
//!
//! A `to_bit` conversion function.
#![doc(primitive = "bool")]

use num::{Int, one, zero};

/////////////////////////////////////////////////////////////////////////////
Expand Down
1 change: 1 addition & 0 deletions src/libcore/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
//! and, as such, should be performed via the `from_u32` function..
#![allow(non_snake_case_functions)]
#![doc(primitive = "char")]

use mem::transmute;
use option::{None, Option, Some};
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/num/f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

//! Operations and constants for 32-bits floats (`f32` type)
#![doc(primitive = "f32")]

use intrinsics;
use mem;
use num::{FPNormal, FPCategory, FPZero, FPSubnormal, FPInfinite, FPNaN};
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/num/f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

//! Operations and constants for 64-bits floats (`f64` type)
#![doc(primitive = "f64")]

use intrinsics;
use mem;
use num::{FPNormal, FPCategory, FPZero, FPSubnormal, FPInfinite, FPNaN};
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/num/i16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@

//! Operations and constants for signed 16-bits integers (`i16` type)
#![doc(primitive = "i16")]

int_module!(i16, 16)

2 changes: 2 additions & 0 deletions src/libcore/num/i32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@

//! Operations and constants for signed 32-bits integers (`i32` type)
#![doc(primitive = "i32")]

int_module!(i32, 32)

2 changes: 2 additions & 0 deletions src/libcore/num/i64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@

//! Operations and constants for signed 64-bits integers (`i64` type)
#![doc(primitive = "i64")]

int_module!(i64, 64)

2 changes: 2 additions & 0 deletions src/libcore/num/i8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@

//! Operations and constants for signed 8-bits integers (`i8` type)
#![doc(primitive = "i8")]

int_module!(i8, 8)

2 changes: 2 additions & 0 deletions src/libcore/num/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

//! Operations and constants for architecture-sized signed integers (`int` type)
#![doc(primitive = "int")]

#[cfg(target_word_size = "32")] int_module!(int, 32)
#[cfg(target_word_size = "64")] int_module!(int, 64)

2 changes: 2 additions & 0 deletions src/libcore/num/u16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@

//! Operations and constants for unsigned 16-bits integers (`u16` type)
#![doc(primitive = "u16")]

uint_module!(u16, i16, 16)
2 changes: 2 additions & 0 deletions src/libcore/num/u32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@

//! Operations and constants for unsigned 32-bits integers (`u32` type)
#![doc(primitive = "u32")]

uint_module!(u32, i32, 32)

2 changes: 2 additions & 0 deletions src/libcore/num/u64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@

//! Operations and constants for unsigned 64-bits integer (`u64` type)
#![doc(primitive = "u64")]

uint_module!(u64, i64, 64)

2 changes: 2 additions & 0 deletions src/libcore/num/u8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@

//! Operations and constants for unsigned 8-bits integers (`u8` type)
#![doc(primitive = "u8")]

uint_module!(u8, i8, 8)

2 changes: 2 additions & 0 deletions src/libcore/num/uint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@

//! Operations and constants for architecture-sized unsigned integers (`uint` type)
#![doc(primitive = "uint")]

uint_module!(uint, int, ::int::BITS)

2 changes: 2 additions & 0 deletions src/libcore/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
//!
//! For more details `std::slice`.
#![doc(primitive = "slice")]

use mem::transmute;
use clone::Clone;
use container::Container;
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
//!
//! For more details, see std::str
#![doc(primitive = "str")]

use mem;
use char;
use clone::Clone;
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
//! assert_eq!(d, (0u32, 0.0f32));
//! ```
#![doc(primitive = "tuple")]

use clone::Clone;
#[cfg(not(test))] use cmp::*;
#[cfg(not(test))] use default::Default;
Expand Down
Loading

0 comments on commit f7af780

Please sign in to comment.