Add links in docs for some primitive types

This commit is contained in:
patrick-gu 2021-08-29 12:29:43 -07:00
parent 926f069950
commit 5719d22125
4 changed files with 85 additions and 72 deletions

View file

@ -3,16 +3,16 @@
#[doc(alias = "false")]
/// The boolean type.
///
/// The `bool` represents a value, which could only be either `true` or `false`. If you cast
/// a `bool` into an integer, `true` will be 1 and `false` will be 0.
/// The `bool` represents a value, which could only be either [`true`] or [`false`]. If you cast
/// a `bool` into an integer, [`true`] will be 1 and [`false`] will be 0.
///
/// # Basic usage
///
/// `bool` implements various traits, such as [`BitAnd`], [`BitOr`], [`Not`], etc.,
/// which allow us to perform boolean operations using `&`, `|` and `!`.
///
/// `if` requires a `bool` value as its conditional. [`assert!`], which is an
/// important macro in testing, checks whether an expression is `true` and panics
/// [`if`] requires a `bool` value as its conditional. [`assert!`], which is an
/// important macro in testing, checks whether an expression is [`true`] and panics
/// if it isn't.
///
/// ```
@ -20,9 +20,12 @@
/// assert!(!bool_val);
/// ```
///
/// [`true`]: keyword.true.html
/// [`false`]: keyword.false.html
/// [`BitAnd`]: ops::BitAnd
/// [`BitOr`]: ops::BitOr
/// [`Not`]: ops::Not
/// [`if`]: keyword.if.html
///
/// # Examples
///
@ -574,11 +577,11 @@ mod prim_pointer {}
///
/// # Editions
///
/// Prior to Rust 1.53, arrays did not implement `IntoIterator` by value, so the method call
/// `array.into_iter()` auto-referenced into a slice iterator. Right now, the old behavior
/// is preserved in the 2015 and 2018 editions of Rust for compatibility, ignoring
/// `IntoIterator` by value. In the future, the behavior on the 2015 and 2018 edition
/// might be made consistent to the behavior of later editions.
/// Prior to Rust 1.53, arrays did not implement [`IntoIterator`] by value, so the method call
/// <code>array.[into_iter()]</code> auto-referenced into a slice iterator.
/// Right now, the old behavior is preserved in the 2015 and 2018 editions of Rust for
/// compatibility, ignoring [`IntoIterator`] by value. In the future, the behavior on the 2015 and
/// 2018 edition might be made consistent to the behavior of later editions.
///
/// ```rust,edition2018
/// # #![allow(array_into_iter)] // override our `deny(warnings)`
@ -604,8 +607,9 @@ mod prim_pointer {}
/// }
/// ```
///
/// Starting in the 2021 edition, `array.into_iter()` will use `IntoIterator` normally to iterate
/// by value, and `iter()` should be used to iterate by reference like previous editions.
/// Starting in the 2021 edition, <code>array.[into_iter()]</code> will use [`IntoIterator`]
/// normally to iterate by value, and [`iter()`](slice::iter) should be used to iterate by
/// reference like previous editions.
///
/// ```rust,edition2021,ignore
/// # // FIXME: ignored because 2021 testing is still unstable
@ -624,16 +628,16 @@ mod prim_pointer {}
/// }
/// ```
///
/// Future language versions might start treating the `array.into_iter()`
/// Future language versions might start treating the <code>array.[into_iter()]</code>
/// syntax on editions 2015 and 2018 the same as on edition 2021. So code using
/// those older editions should still be written with this change in mind, to
/// prevent breakage in the future. The safest way to accomplish this is to
/// avoid the `into_iter` syntax on those editions. If an edition update is not
/// viable/desired, there are multiple alternatives:
/// * use `iter`, equivalent to the old behavior, creating references
/// avoid the [`into_iter`](IntoIterator::into_iter) syntax on those editions.
/// If an edition update is not viable/desired, there are multiple alternatives:
/// * use [`iter`](slice::iter), equivalent to the old behavior, creating references
/// * use [`array::IntoIter`], equivalent to the post-2021 behavior (Rust 1.51+)
/// * replace `for ... in array.into_iter() {` with `for ... in array {`,
/// equivalent to the post-2021 behavior (Rust 1.53+)
/// * replace <code>[for] ... [in] array.[into_iter()] {</code>` with
/// <code>[for] ... [in] array {</code>, equivalent to the post-2021 behavior (Rust 1.53+)
///
/// ```rust,edition2018
/// use std::array::IntoIter;
@ -672,6 +676,9 @@ mod prim_pointer {}
/// [`Borrow`]: borrow::Borrow
/// [`BorrowMut`]: borrow::BorrowMut
/// [slice pattern]: ../reference/patterns.html#slice-patterns
/// [into_iter()]: IntoIterator::into_iter
/// [for]: keyword.for.html
/// [in]: keyword.in.html
#[stable(feature = "rust1", since = "1.0.0")]
mod prim_array {}
@ -829,7 +836,7 @@ mod prim_str {}
/// ```
///
/// The sequential nature of the tuple applies to its implementations of various
/// traits. For example, in `PartialOrd` and `Ord`, the elements are compared
/// traits. For example, in [`PartialOrd`] and [`Ord`], the elements are compared
/// sequentially until the first non-equal set is found.
///
/// For more about tuples, see [the book](../book/ch03-02-data-types.html#the-tuple-type).
@ -1033,14 +1040,16 @@ mod prim_usize {}
/// References, both shared and mutable.
///
/// A reference represents a borrow of some owned value. You can get one by using the `&` or `&mut`
/// operators on a value, or by using a `ref` or `ref mut` pattern.
/// operators on a value, or by using a [`ref`](keyword.ref.html) or
/// <code>[ref](keyword.ref.html) [mut](keyword.mut.html)</code> pattern.
///
/// For those familiar with pointers, a reference is just a pointer that is assumed to be
/// aligned, not null, and pointing to memory containing a valid value of `T` - for example,
/// `&bool` can only point to an allocation containing the integer values `1` (`true`) or `0`
/// (`false`), but creating a `&bool` that points to an allocation containing
/// the value `3` causes undefined behaviour.
/// In fact, `Option<&T>` has the same memory representation as a
/// <code>&[bool]</code> can only point to an allocation containing the integer values `1`
/// ([`true`](keyword.true.html)) or `0` ([`false`](keyword.false.html)), but creating a
/// <code>&[bool]</code> that points to an allocation containing the value `3` causes
/// undefined behaviour.
/// In fact, <code>[Option]\<&T></code> has the same memory representation as a
/// nullable but aligned pointer, and can be passed across FFI boundaries as such.
///
/// In most cases, references can be used much like the original value. Field access, method
@ -1088,7 +1097,7 @@ mod prim_usize {}
/// The following traits are implemented for all `&T`, regardless of the type of its referent:
///
/// * [`Copy`]
/// * [`Clone`] \(Note that this will not defer to `T`'s `Clone` implementation if it exists!)
/// * [`Clone`] \(Note that this will not defer to `T`'s [`Clone`] implementation if it exists!)
/// * [`Deref`]
/// * [`Borrow`]
/// * [`Pointer`]
@ -1097,7 +1106,7 @@ mod prim_usize {}
/// [`Borrow`]: borrow::Borrow
/// [`Pointer`]: fmt::Pointer
///
/// `&mut T` references get all of the above except `Copy` and `Clone` (to prevent creating
/// `&mut T` references get all of the above except [`Copy`] and [`Clone`] (to prevent creating
/// multiple simultaneous mutable borrows), plus the following, regardless of the type of its
/// referent:
///
@ -1125,18 +1134,18 @@ mod prim_usize {}
/// [`Hash`]: hash::Hash
/// [`ToSocketAddrs`]: net::ToSocketAddrs
///
/// `&mut T` references get all of the above except `ToSocketAddrs`, plus the following, if `T`
/// `&mut T` references get all of the above except [`ToSocketAddrs`], plus the following, if `T`
/// implements that trait:
///
/// * [`AsMut`]
/// * [`FnMut`] \(in addition, `&mut T` references get [`FnOnce`] if `T: FnMut`)
/// * [`FnMut`] \(in addition, `&mut T` references get [`FnOnce`] if <code>T: [FnMut]</code>)
/// * [`fmt::Write`]
/// * [`Iterator`]
/// * [`DoubleEndedIterator`]
/// * [`ExactSizeIterator`]
/// * [`FusedIterator`]
/// * [`TrustedLen`]
/// * [`Send`] \(note that `&T` references only get `Send` if `T: Sync`)
/// * [`Send`] \(note that `&T` references only get [`Send`] if <code>T: [Sync]</code>)
/// * [`io::Write`]
/// * [`Read`]
/// * [`Seek`]
@ -1168,7 +1177,7 @@ mod prim_ref {}
/// Function pointers are pointers that point to *code*, not data. They can be called
/// just like functions. Like references, function pointers are, among other things, assumed to
/// not be null, so if you want to pass a function pointer over FFI and be able to accommodate null
/// pointers, make your type `Option<fn()>` with your required signature.
/// pointers, make your type <code>[Option]\<fn()></code> with your required signature.
///
/// ### Safety
///