Skip to content

Commit 0961e68

Browse files
committed
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!
2 parents 3baa466 + 7c32b58 commit 0961e68

File tree

4 files changed

+33
-25
lines changed

4 files changed

+33
-25
lines changed

library/core/src/array/mod.rs

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

library/core/src/bool.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
#[lang = "bool"]
44
impl bool {
5-
/// Returns `Some(t)` if the `bool` is `true`, or `None` otherwise.
5+
/// Returns `Some(t)` if the `bool` is [`true`](keyword.true.html), or `None` otherwise.
66
///
77
/// # Examples
88
///
@@ -18,7 +18,7 @@ impl bool {
1818
if self { Some(t) } else { None }
1919
}
2020

21-
/// Returns `Some(f())` if the `bool` is `true`, or `None` otherwise.
21+
/// Returns `Some(f())` if the `bool` is [`true`](keyword.true.html), or `None` otherwise.
2222
///
2323
/// # Examples
2424
///

library/core/src/char/methods.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl char {
9696
/// Converts a `u32` to a `char`.
9797
///
9898
/// Note that all `char`s are valid [`u32`]s, and can be cast to one with
99-
/// `as`:
99+
/// [`as`](keyword.as.html):
100100
///
101101
/// ```
102102
/// let c = '💯';
@@ -372,7 +372,7 @@ impl char {
372372
/// println!("\\u{{2764}}");
373373
/// ```
374374
///
375-
/// Using `to_string`:
375+
/// Using [`to_string`](string/trait.ToString.html#tymethod.to_string):
376376
///
377377
/// ```
378378
/// assert_eq!('❤'.escape_unicode().to_string(), "\\u{2764}");
@@ -422,7 +422,7 @@ impl char {
422422
/// Returns an iterator that yields the literal escape code of a character
423423
/// as `char`s.
424424
///
425-
/// This will escape the characters similar to the `Debug` implementations
425+
/// This will escape the characters similar to the [`Debug`](core::fmt::Debug) implementations
426426
/// of `str` or `char`.
427427
///
428428
/// # Examples
@@ -448,7 +448,7 @@ impl char {
448448
/// println!("\\n");
449449
/// ```
450450
///
451-
/// Using `to_string`:
451+
/// Using [`to_string`](string/trait.ToString.html#tymethod.to_string):
452452
///
453453
/// ```
454454
/// assert_eq!('\n'.escape_debug().to_string(), "\\n");
@@ -502,7 +502,7 @@ impl char {
502502
/// println!("\\\"");
503503
/// ```
504504
///
505-
/// Using `to_string`:
505+
/// Using [`to_string`](string/trait.ToString.html#tymethod.to_string):
506506
///
507507
/// ```
508508
/// assert_eq!('"'.escape_default().to_string(), "\\\"");
@@ -937,7 +937,7 @@ impl char {
937937
/// println!("i\u{307}");
938938
/// ```
939939
///
940-
/// Using `to_string`:
940+
/// Using [`to_string`](string/trait.ToString.html#tymethod.to_string):
941941
///
942942
/// ```
943943
/// assert_eq!('C'.to_lowercase().to_string(), "c");
@@ -1002,7 +1002,7 @@ impl char {
10021002
/// println!("SS");
10031003
/// ```
10041004
///
1005-
/// Using `to_string`:
1005+
/// Using [`to_string`](string/trait.ToString.html#tymethod.to_string):
10061006
///
10071007
/// ```
10081008
/// assert_eq!('c'.to_uppercase().to_string(), "C");
@@ -1131,7 +1131,7 @@ impl char {
11311131

11321132
/// Checks that two values are an ASCII case-insensitive match.
11331133
///
1134-
/// Equivalent to `to_ascii_lowercase(a) == to_ascii_lowercase(b)`.
1134+
/// Equivalent to <code>[to_ascii_lowercase]\(a) == [to_ascii_lowercase]\(b)</code>.
11351135
///
11361136
/// # Examples
11371137
///
@@ -1144,6 +1144,8 @@ impl char {
11441144
/// assert!(upper_a.eq_ignore_ascii_case(&upper_a));
11451145
/// assert!(!upper_a.eq_ignore_ascii_case(&lower_z));
11461146
/// ```
1147+
///
1148+
/// [to_ascii_lowercase]: #method.to_ascii_lowercase
11471149
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
11481150
#[rustc_const_stable(feature = "const_ascii_methods_on_intrinsics", since = "1.52.0")]
11491151
#[inline]

library/std/src/primitive_docs.rs

+20-14
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,29 @@
33
#[doc(alias = "false")]
44
/// The boolean type.
55
///
6-
/// The `bool` represents a value, which could only be either `true` or `false`. If you cast
7-
/// a `bool` into an integer, `true` will be 1 and `false` will be 0.
6+
/// The `bool` represents a value, which could only be either [`true`] or [`false`]. If you cast
7+
/// a `bool` into an integer, [`true`] will be 1 and [`false`] will be 0.
88
///
99
/// # Basic usage
1010
///
1111
/// `bool` implements various traits, such as [`BitAnd`], [`BitOr`], [`Not`], etc.,
1212
/// which allow us to perform boolean operations using `&`, `|` and `!`.
1313
///
14-
/// `if` requires a `bool` value as its conditional. [`assert!`], which is an
15-
/// important macro in testing, checks whether an expression is `true` and panics
14+
/// [`if`] requires a `bool` value as its conditional. [`assert!`], which is an
15+
/// important macro in testing, checks whether an expression is [`true`] and panics
1616
/// if it isn't.
1717
///
1818
/// ```
1919
/// let bool_val = true & false | false;
2020
/// assert!(!bool_val);
2121
/// ```
2222
///
23+
/// [`true`]: keyword.true.html
24+
/// [`false`]: keyword.false.html
2325
/// [`BitAnd`]: ops::BitAnd
2426
/// [`BitOr`]: ops::BitOr
2527
/// [`Not`]: ops::Not
28+
/// [`if`]: keyword.if.html
2629
///
2730
/// # Examples
2831
///
@@ -574,8 +577,8 @@ mod prim_pointer {}
574577
///
575578
/// # Editions
576579
///
577-
/// Prior to Rust 1.53, arrays did not implement `IntoIterator` by value, so the method call
578-
/// `array.into_iter()` auto-referenced into a slice iterator. Right now, the old behavior
580+
/// Prior to Rust 1.53, arrays did not implement [`IntoIterator`] by value, so the method call
581+
/// `array.into_iter()` auto-referenced into a [slice iterator](slice::iter). Right now, the old behavior
579582
/// is preserved in the 2015 and 2018 editions of Rust for compatibility, ignoring
580583
/// `IntoIterator` by value. In the future, the behavior on the 2015 and 2018 edition
581584
/// might be made consistent to the behavior of later editions.
@@ -833,7 +836,7 @@ mod prim_str {}
833836
/// ```
834837
///
835838
/// The sequential nature of the tuple applies to its implementations of various
836-
/// traits. For example, in `PartialOrd` and `Ord`, the elements are compared
839+
/// traits. For example, in [`PartialOrd`] and [`Ord`], the elements are compared
837840
/// sequentially until the first non-equal set is found.
838841
///
839842
/// For more about tuples, see [the book](../book/ch03-02-data-types.html#the-tuple-type).
@@ -1037,14 +1040,16 @@ mod prim_usize {}
10371040
/// References, both shared and mutable.
10381041
///
10391042
/// A reference represents a borrow of some owned value. You can get one by using the `&` or `&mut`
1040-
/// operators on a value, or by using a `ref` or `ref mut` pattern.
1043+
/// operators on a value, or by using a [`ref`](keyword.ref.html) or
1044+
/// <code>[ref](keyword.ref.html) [mut](keyword.mut.html)</code> pattern.
10411045
///
10421046
/// For those familiar with pointers, a reference is just a pointer that is assumed to be
10431047
/// aligned, not null, and pointing to memory containing a valid value of `T` - for example,
1044-
/// `&bool` can only point to an allocation containing the integer values `1` (`true`) or `0`
1045-
/// (`false`), but creating a `&bool` that points to an allocation containing
1046-
/// the value `3` causes undefined behaviour.
1047-
/// In fact, `Option<&T>` has the same memory representation as a
1048+
/// <code>&[bool]</code> can only point to an allocation containing the integer values `1`
1049+
/// ([`true`](keyword.true.html)) or `0` ([`false`](keyword.false.html)), but creating a
1050+
/// <code>&[bool]</code> that points to an allocation containing the value `3` causes
1051+
/// undefined behaviour.
1052+
/// In fact, <code>[Option]\<&T></code> has the same memory representation as a
10481053
/// nullable but aligned pointer, and can be passed across FFI boundaries as such.
10491054
///
10501055
/// In most cases, references can be used much like the original value. Field access, method
@@ -1140,7 +1145,7 @@ mod prim_usize {}
11401145
/// * [`ExactSizeIterator`]
11411146
/// * [`FusedIterator`]
11421147
/// * [`TrustedLen`]
1143-
/// * [`Send`] \(note that `&T` references only get `Send` if `T: Sync`)
1148+
/// * [`Send`] \(note that `&T` references only get `Send` if <code>T: [Sync]</code>)
11441149
/// * [`io::Write`]
11451150
/// * [`Read`]
11461151
/// * [`Seek`]
@@ -1172,7 +1177,8 @@ mod prim_ref {}
11721177
/// Function pointers are pointers that point to *code*, not data. They can be called
11731178
/// just like functions. Like references, function pointers are, among other things, assumed to
11741179
/// not be null, so if you want to pass a function pointer over FFI and be able to accommodate null
1175-
/// pointers, make your type `Option<fn()>` with your required signature.
1180+
/// pointers, make your type [`Option<fn()>`](core::option#options-and-pointers-nullable-pointers)
1181+
/// with your required signature.
11761182
///
11771183
/// ### Safety
11781184
///

0 commit comments

Comments
 (0)