Auto merge of #88469 - patrick-gu:master, r=dtolnay

Add links in docs for some primitive types

This pull request adds additional links in existing documentation of some of the primitive types.

Where items are linked only once, I have used the `[link](destination)` format. For items in `std`, I have linked directly to the HTML, since although the primitives are in `core`, they are not displayed on `core` documentation. I was unsure of what length I should keep lines of documentation to, so I tried to keep them within reason.

Additionally, I have avoided excessively linking to keywords like `self` when they are not relevant to the documentation. I can add these links if it would be an improvement.

I hope this can improve Rust. Please let me know if there's anything I did wrong!
This commit is contained in:
bors 2021-09-05 01:56:25 +00:00
commit 0961e688fd
4 changed files with 33 additions and 25 deletions

View File

@ -396,7 +396,7 @@ impl<T, const N: usize> [T; N] {
/// ///
/// This method is particularly useful if combined with other methods, like /// This method is particularly useful if combined with other methods, like
/// [`map`](#method.map). This way, you can avoid moving the original /// [`map`](#method.map). This way, you can avoid moving the original
/// array if its elements are not `Copy`. /// array if its elements are not [`Copy`].
/// ///
/// ``` /// ```
/// #![feature(array_methods)] /// #![feature(array_methods)]

View File

@ -2,7 +2,7 @@
#[lang = "bool"] #[lang = "bool"]
impl bool { impl bool {
/// Returns `Some(t)` if the `bool` is `true`, or `None` otherwise. /// Returns `Some(t)` if the `bool` is [`true`](keyword.true.html), or `None` otherwise.
/// ///
/// # Examples /// # Examples
/// ///
@ -18,7 +18,7 @@ impl bool {
if self { Some(t) } else { None } if self { Some(t) } else { None }
} }
/// Returns `Some(f())` if the `bool` is `true`, or `None` otherwise. /// Returns `Some(f())` if the `bool` is [`true`](keyword.true.html), or `None` otherwise.
/// ///
/// # Examples /// # Examples
/// ///

View File

@ -96,7 +96,7 @@ impl char {
/// Converts a `u32` to a `char`. /// Converts a `u32` to a `char`.
/// ///
/// Note that all `char`s are valid [`u32`]s, and can be cast to one with /// Note that all `char`s are valid [`u32`]s, and can be cast to one with
/// `as`: /// [`as`](keyword.as.html):
/// ///
/// ``` /// ```
/// let c = '💯'; /// let c = '💯';
@ -372,7 +372,7 @@ impl char {
/// println!("\\u{{2764}}"); /// println!("\\u{{2764}}");
/// ``` /// ```
/// ///
/// Using `to_string`: /// Using [`to_string`](string/trait.ToString.html#tymethod.to_string):
/// ///
/// ``` /// ```
/// assert_eq!('❤'.escape_unicode().to_string(), "\\u{2764}"); /// assert_eq!('❤'.escape_unicode().to_string(), "\\u{2764}");
@ -422,7 +422,7 @@ impl char {
/// Returns an iterator that yields the literal escape code of a character /// Returns an iterator that yields the literal escape code of a character
/// as `char`s. /// as `char`s.
/// ///
/// This will escape the characters similar to the `Debug` implementations /// This will escape the characters similar to the [`Debug`](core::fmt::Debug) implementations
/// of `str` or `char`. /// of `str` or `char`.
/// ///
/// # Examples /// # Examples
@ -448,7 +448,7 @@ impl char {
/// println!("\\n"); /// println!("\\n");
/// ``` /// ```
/// ///
/// Using `to_string`: /// Using [`to_string`](string/trait.ToString.html#tymethod.to_string):
/// ///
/// ``` /// ```
/// assert_eq!('\n'.escape_debug().to_string(), "\\n"); /// assert_eq!('\n'.escape_debug().to_string(), "\\n");
@ -502,7 +502,7 @@ impl char {
/// println!("\\\""); /// println!("\\\"");
/// ``` /// ```
/// ///
/// Using `to_string`: /// Using [`to_string`](string/trait.ToString.html#tymethod.to_string):
/// ///
/// ``` /// ```
/// assert_eq!('"'.escape_default().to_string(), "\\\""); /// assert_eq!('"'.escape_default().to_string(), "\\\"");
@ -937,7 +937,7 @@ impl char {
/// println!("i\u{307}"); /// println!("i\u{307}");
/// ``` /// ```
/// ///
/// Using `to_string`: /// Using [`to_string`](string/trait.ToString.html#tymethod.to_string):
/// ///
/// ``` /// ```
/// assert_eq!('C'.to_lowercase().to_string(), "c"); /// assert_eq!('C'.to_lowercase().to_string(), "c");
@ -1002,7 +1002,7 @@ impl char {
/// println!("SS"); /// println!("SS");
/// ``` /// ```
/// ///
/// Using `to_string`: /// Using [`to_string`](string/trait.ToString.html#tymethod.to_string):
/// ///
/// ``` /// ```
/// assert_eq!('c'.to_uppercase().to_string(), "C"); /// assert_eq!('c'.to_uppercase().to_string(), "C");
@ -1131,7 +1131,7 @@ impl char {
/// Checks that two values are an ASCII case-insensitive match. /// Checks that two values are an ASCII case-insensitive match.
/// ///
/// Equivalent to `to_ascii_lowercase(a) == to_ascii_lowercase(b)`. /// Equivalent to <code>[to_ascii_lowercase]\(a) == [to_ascii_lowercase]\(b)</code>.
/// ///
/// # Examples /// # Examples
/// ///
@ -1144,6 +1144,8 @@ impl char {
/// assert!(upper_a.eq_ignore_ascii_case(&upper_a)); /// assert!(upper_a.eq_ignore_ascii_case(&upper_a));
/// assert!(!upper_a.eq_ignore_ascii_case(&lower_z)); /// assert!(!upper_a.eq_ignore_ascii_case(&lower_z));
/// ``` /// ```
///
/// [to_ascii_lowercase]: #method.to_ascii_lowercase
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")] #[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
#[rustc_const_stable(feature = "const_ascii_methods_on_intrinsics", since = "1.52.0")] #[rustc_const_stable(feature = "const_ascii_methods_on_intrinsics", since = "1.52.0")]
#[inline] #[inline]

View File

@ -3,16 +3,16 @@
#[doc(alias = "false")] #[doc(alias = "false")]
/// The boolean type. /// The boolean type.
/// ///
/// The `bool` represents a value, which could only be either `true` or `false`. If you cast /// 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. /// a `bool` into an integer, [`true`] will be 1 and [`false`] will be 0.
/// ///
/// # Basic usage /// # Basic usage
/// ///
/// `bool` implements various traits, such as [`BitAnd`], [`BitOr`], [`Not`], etc., /// `bool` implements various traits, such as [`BitAnd`], [`BitOr`], [`Not`], etc.,
/// which allow us to perform boolean operations using `&`, `|` and `!`. /// which allow us to perform boolean operations using `&`, `|` and `!`.
/// ///
/// `if` requires a `bool` value as its conditional. [`assert!`], which is an /// [`if`] requires a `bool` value as its conditional. [`assert!`], which is an
/// important macro in testing, checks whether an expression is `true` and panics /// important macro in testing, checks whether an expression is [`true`] and panics
/// if it isn't. /// if it isn't.
/// ///
/// ``` /// ```
@ -20,9 +20,12 @@
/// assert!(!bool_val); /// assert!(!bool_val);
/// ``` /// ```
/// ///
/// [`true`]: keyword.true.html
/// [`false`]: keyword.false.html
/// [`BitAnd`]: ops::BitAnd /// [`BitAnd`]: ops::BitAnd
/// [`BitOr`]: ops::BitOr /// [`BitOr`]: ops::BitOr
/// [`Not`]: ops::Not /// [`Not`]: ops::Not
/// [`if`]: keyword.if.html
/// ///
/// # Examples /// # Examples
/// ///
@ -574,8 +577,8 @@ mod prim_pointer {}
/// ///
/// # Editions /// # Editions
/// ///
/// Prior to Rust 1.53, arrays did not implement `IntoIterator` by value, so the method call /// 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 /// `array.into_iter()` auto-referenced into a [slice iterator](slice::iter). Right now, the old behavior
/// is preserved in the 2015 and 2018 editions of Rust for compatibility, ignoring /// 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 /// `IntoIterator` by value. In the future, the behavior on the 2015 and 2018 edition
/// might be made consistent to the behavior of later editions. /// might be made consistent to the behavior of later editions.
@ -833,7 +836,7 @@ mod prim_str {}
/// ``` /// ```
/// ///
/// The sequential nature of the tuple applies to its implementations of various /// 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. /// 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). /// For more about tuples, see [the book](../book/ch03-02-data-types.html#the-tuple-type).
@ -1037,14 +1040,16 @@ mod prim_usize {}
/// References, both shared and mutable. /// References, both shared and mutable.
/// ///
/// A reference represents a borrow of some owned value. You can get one by using the `&` or `&mut` /// 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 /// 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, /// 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` /// <code>&[bool]</code> can only point to an allocation containing the integer values `1`
/// (`false`), but creating a `&bool` that points to an allocation containing /// ([`true`](keyword.true.html)) or `0` ([`false`](keyword.false.html)), but creating a
/// the value `3` causes undefined behaviour. /// <code>&[bool]</code> that points to an allocation containing the value `3` causes
/// In fact, `Option<&T>` has the same memory representation as a /// 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. /// 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 /// In most cases, references can be used much like the original value. Field access, method
@ -1140,7 +1145,7 @@ mod prim_usize {}
/// * [`ExactSizeIterator`] /// * [`ExactSizeIterator`]
/// * [`FusedIterator`] /// * [`FusedIterator`]
/// * [`TrustedLen`] /// * [`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`] /// * [`io::Write`]
/// * [`Read`] /// * [`Read`]
/// * [`Seek`] /// * [`Seek`]
@ -1172,7 +1177,8 @@ mod prim_ref {}
/// Function pointers are pointers that point to *code*, not data. They can be called /// 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 /// 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 /// 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 [`Option<fn()>`](core::option#options-and-pointers-nullable-pointers)
/// with your required signature.
/// ///
/// ### Safety /// ### Safety
/// ///