Skip to content

Commit addb4da

Browse files
committedSep 25, 2021
Auto merge of rust-lang#88343 - steffahn:fix_code_spacing, r=jyn514
Fix spacing of links in inline code. Similar to rust-lang#80733, but the focus is different. This PR eliminates all occurrences of pieced-together inline code blocks like [`Box`]`<`[`Option`]`<T>>` and replaces them with good-looking ones (using HTML-syntax), like <code>[Box]<[Option]\<T>></code>. As far as I can tell, I should’ve found all of these in the standard library (regex search with `` r"`\]`|`\[`" ``) \[except for in `core::convert` where I’ve noticed other things in the docs that I want to fix in a separate PR]. In particular, unlike rust-lang#80733, I’ve added almost no new instance of inline code that’s broken up into multiple links (or some link and some link-free part). I also added tooltips (the stuff in quotes for the markdown link listings) in places that caught my eye, but that’s by no means systematic, just opportunistic. [Box]: https://doc.rust-lang.org/std/boxed/struct.Box.html "Box" [`Box`]: https://doc.rust-lang.org/std/boxed/struct.Box.html "Box" [Option]: https://doc.rust-lang.org/std/option/enum.Option.html "Option" [`Option`]: https://doc.rust-lang.org/std/option/enum.Option.html "Option" Context: I got annoyed by repeatedly running into new misformatted inline code while reading the standard library docs. I know that once issue rust-lang#83997 (and/or related ones) are resolved, these changes become somewhat obsolete, but I fail to notice much progress on that end right now. r? `@jyn514`
2 parents 9620f3a + 67065fe commit addb4da

File tree

26 files changed

+226
-235
lines changed

26 files changed

+226
-235
lines changed
 

‎library/alloc/src/fmt.rs

+12-16
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@
348348
//! provides some helper methods.
349349
//!
350350
//! Additionally, the return value of this function is [`fmt::Result`] which is a
351-
//! type alias of [`Result`]`<(), `[`std::fmt::Error`]`>`. Formatting implementations
351+
//! type alias of <code>[Result]<(), [std::fmt::Error]></code>. Formatting implementations
352352
//! should ensure that they propagate errors from the [`Formatter`] (e.g., when
353353
//! calling [`write!`]). However, they should never return errors spuriously. That
354354
//! is, a formatting implementation must and may only return an error if the
@@ -505,23 +505,19 @@
505505
//! it would internally pass around this structure until it has been determined
506506
//! where output should go to.
507507
//!
508-
//! [`fmt::Result`]: Result
509-
//! [`Result`]: core::result::Result
510-
//! [`std::fmt::Error`]: Error
511-
//! [`write!`]: core::write
512-
//! [`write`]: core::write
513-
//! [`format!`]: crate::format
514-
//! [`to_string`]: crate::string::ToString
515-
//! [`writeln!`]: core::writeln
508+
//! [`fmt::Result`]: Result "fmt::Result"
509+
//! [Result]: core::result::Result "std::result::Result"
510+
//! [std::fmt::Error]: Error "fmt::Error"
511+
//! [`write`]: write() "fmt::write"
512+
//! [`to_string`]: crate::string::ToString::to_string "ToString::to_string"
516513
//! [`write_fmt`]: ../../std/io/trait.Write.html#method.write_fmt
517514
//! [`std::io::Write`]: ../../std/io/trait.Write.html
518-
//! [`print!`]: ../../std/macro.print.html
519-
//! [`println!`]: ../../std/macro.println.html
520-
//! [`eprint!`]: ../../std/macro.eprint.html
521-
//! [`eprintln!`]: ../../std/macro.eprintln.html
522-
//! [`format_args!`]: core::format_args
523-
//! [`fmt::Arguments`]: Arguments
524-
//! [`format`]: crate::format
515+
//! [`print!`]: ../../std/macro.print.html "print!"
516+
//! [`println!`]: ../../std/macro.println.html "println!"
517+
//! [`eprint!`]: ../../std/macro.eprint.html "eprint!"
518+
//! [`eprintln!`]: ../../std/macro.eprintln.html "eprintln!"
519+
//! [`fmt::Arguments`]: Arguments "fmt::Arguments"
520+
//! [`format`]: format() "fmt::format"
525521
526522
#![stable(feature = "rust1", since = "1.0.0")]
527523

‎library/alloc/src/rc.rs

+4-12
Original file line numberDiff line numberDiff line change
@@ -781,9 +781,7 @@ impl<T: ?Sized> Rc<T> {
781781
/// Consumes the `Rc`, returning the wrapped pointer.
782782
///
783783
/// To avoid a memory leak the pointer must be converted back to an `Rc` using
784-
/// [`Rc::from_raw`][from_raw].
785-
///
786-
/// [from_raw]: Rc::from_raw
784+
/// [`Rc::from_raw`].
787785
///
788786
/// # Examples
789787
///
@@ -834,7 +832,7 @@ impl<T: ?Sized> Rc<T> {
834832
/// and alignment as `T`. This is trivially true if `U` is `T`.
835833
/// Note that if `U` is not `T` but has the same size and alignment, this is
836834
/// basically like transmuting references of different types. See
837-
/// [`mem::transmute`][transmute] for more information on what
835+
/// [`mem::transmute`] for more information on what
838836
/// restrictions apply in this case.
839837
///
840838
/// The user of `from_raw` has to make sure a specific value of `T` is only
@@ -844,7 +842,6 @@ impl<T: ?Sized> Rc<T> {
844842
/// even if the returned `Rc<T>` is never accessed.
845843
///
846844
/// [into_raw]: Rc::into_raw
847-
/// [transmute]: core::mem::transmute
848845
///
849846
/// # Examples
850847
///
@@ -1086,8 +1083,6 @@ impl<T: ?Sized> Rc<T> {
10861083
/// assert!(Rc::ptr_eq(&five, &same_five));
10871084
/// assert!(!Rc::ptr_eq(&five, &other_five));
10881085
/// ```
1089-
///
1090-
/// [`ptr::eq`]: core::ptr::eq
10911086
pub fn ptr_eq(this: &Self, other: &Self) -> bool {
10921087
this.ptr.as_ptr() == other.ptr.as_ptr()
10931088
}
@@ -1993,7 +1988,7 @@ impl<T, I: iter::TrustedLen<Item = T>> ToRcSlice<T> for I {
19931988

19941989
/// `Weak` is a version of [`Rc`] that holds a non-owning reference to the
19951990
/// managed allocation. The allocation is accessed by calling [`upgrade`] on the `Weak`
1996-
/// pointer, which returns an [`Option`]`<`[`Rc`]`<T>>`.
1991+
/// pointer, which returns an <code>[Option]<[Rc]\<T>></code>.
19971992
///
19981993
/// Since a `Weak` reference does not count towards ownership, it will not
19991994
/// prevent the value stored in the allocation from being dropped, and `Weak` itself makes no
@@ -2090,7 +2085,7 @@ impl<T: ?Sized> Weak<T> {
20902085
/// // assert_eq!("hello", unsafe { &*weak.as_ptr() });
20912086
/// ```
20922087
///
2093-
/// [`null`]: core::ptr::null
2088+
/// [`null`]: ptr::null
20942089
#[stable(feature = "rc_as_ptr", since = "1.45.0")]
20952090
pub fn as_ptr(&self) -> *const T {
20962091
let ptr: *mut RcBox<T> = NonNull::as_ptr(self.ptr);
@@ -2317,8 +2312,6 @@ impl<T: ?Sized> Weak<T> {
23172312
/// let third = Rc::downgrade(&third_rc);
23182313
/// assert!(!first.ptr_eq(&third));
23192314
/// ```
2320-
///
2321-
/// [`ptr::eq`]: core::ptr::eq
23222315
#[inline]
23232316
#[stable(feature = "weak_ptr_eq", since = "1.39.0")]
23242317
pub fn ptr_eq(&self, other: &Self) -> bool {
@@ -2400,7 +2393,6 @@ impl<T> Default for Weak<T> {
24002393
/// Constructs a new `Weak<T>`, without allocating any memory.
24012394
/// Calling [`upgrade`] on the return value always gives [`None`].
24022395
///
2403-
/// [`None`]: Option
24042396
/// [`upgrade`]: Weak::upgrade
24052397
///
24062398
/// # Examples

‎library/alloc/src/string.rs

+25-23
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ use crate::vec::Vec;
7979
///
8080
/// # Examples
8181
///
82-
/// You can create a `String` from [a literal string][`str`] with [`String::from`]:
82+
/// You can create a `String` from [a literal string][`&str`] with [`String::from`]:
8383
///
8484
/// [`String::from`]: From::from
8585
///
@@ -128,7 +128,7 @@ use crate::vec::Vec;
128128
/// println!("The first letter of s is {}", s[0]); // ERROR!!!
129129
/// ```
130130
///
131-
/// [`OsString`]: ../../std/ffi/struct.OsString.html
131+
/// [`OsString`]: ../../std/ffi/struct.OsString.html "ffi::OsString"
132132
///
133133
/// Indexing is intended to be a constant-time operation, but UTF-8 encoding
134134
/// does not allow us to do this. Furthermore, it's not clear what sort of
@@ -141,7 +141,7 @@ use crate::vec::Vec;
141141
///
142142
/// # Deref
143143
///
144-
/// `String`s implement [`Deref`]`<Target=str>`, and so inherit all of [`str`]'s
144+
/// `String` implements <code>[Deref]<Target = [str]></code>, and so inherits all of [`str`]'s
145145
/// methods. In addition, this means that you can pass a `String` to a
146146
/// function which takes a [`&str`] by using an ampersand (`&`):
147147
///
@@ -182,7 +182,7 @@ use crate::vec::Vec;
182182
/// to explicitly extract the string slice containing the string. The second
183183
/// way changes `example_func(&example_string);` to
184184
/// `example_func(&*example_string);`. In this case we are dereferencing a
185-
/// `String` to a [`str`][`&str`], then referencing the [`str`][`&str`] back to
185+
/// `String` to a [`str`], then referencing the [`str`] back to
186186
/// [`&str`]. The second way is more idiomatic, however both work to do the
187187
/// conversion explicitly rather than relying on the implicit conversion.
188188
///
@@ -282,9 +282,11 @@ use crate::vec::Vec;
282282
///
283283
/// Here, there's no need to allocate more memory inside the loop.
284284
///
285-
/// [`str`]: prim@str
286-
/// [`&str`]: prim@str
287-
/// [`Deref`]: core::ops::Deref
285+
/// [str]: prim@str "str"
286+
/// [`str`]: prim@str "str"
287+
/// [`&str`]: prim@str "&str"
288+
/// [Deref]: core::ops::Deref "ops::Deref"
289+
/// [`Deref`]: core::ops::Deref "ops::Deref"
288290
/// [`as_str()`]: String::as_str
289291
#[derive(PartialOrd, Eq, Ord)]
290292
#[cfg_attr(not(test), rustc_diagnostic_item = "string_type")]
@@ -308,10 +310,10 @@ pub struct String {
308310
/// an analogue to `FromUtf8Error`, and you can get one from a `FromUtf8Error`
309311
/// through the [`utf8_error`] method.
310312
///
311-
/// [`Utf8Error`]: core::str::Utf8Error
312-
/// [`std::str`]: core::str
313-
/// [`&str`]: prim@str
314-
/// [`utf8_error`]: Self::utf8_error
313+
/// [`Utf8Error`]: str::Utf8Error "std::str::Utf8Error"
314+
/// [`std::str`]: core::str "std::str"
315+
/// [`&str`]: prim@str "&str"
316+
/// [`utf8_error`]: FromUtf8Error::utf8_error
315317
///
316318
/// # Examples
317319
///
@@ -487,8 +489,8 @@ impl String {
487489
/// with this error.
488490
///
489491
/// [`from_utf8_unchecked`]: String::from_utf8_unchecked
490-
/// [`Vec<u8>`]: crate::vec::Vec
491-
/// [`&str`]: prim@str
492+
/// [`Vec<u8>`]: crate::vec::Vec "Vec"
493+
/// [`&str`]: prim@str "&str"
492494
/// [`into_bytes`]: String::into_bytes
493495
#[inline]
494496
#[stable(feature = "rust1", since = "1.0.0")]
@@ -524,7 +526,7 @@ impl String {
524526
/// it's already valid UTF-8, we don't need a new allocation. This return
525527
/// type allows us to handle both cases.
526528
///
527-
/// [`Cow<'a, str>`]: crate::borrow::Cow
529+
/// [`Cow<'a, str>`]: crate::borrow::Cow "borrow::Cow"
528530
///
529531
/// # Examples
530532
///
@@ -625,7 +627,7 @@ impl String {
625627
/// conversion requires a memory allocation.
626628
///
627629
/// [`from_utf8_lossy`]: String::from_utf8_lossy
628-
/// [`Cow<'a, str>`]: crate::borrow::Cow
630+
/// [`Cow<'a, str>`]: crate::borrow::Cow "borrow::Cow"
629631
/// [U+FFFD]: core::char::REPLACEMENT_CHARACTER
630632
///
631633
/// # Examples
@@ -1721,11 +1723,11 @@ impl String {
17211723
unsafe { self.as_mut_vec() }.splice((start, end), replace_with.bytes());
17221724
}
17231725

1724-
/// Converts this `String` into a [`Box`]`<`[`str`]`>`.
1726+
/// Converts this `String` into a <code>[Box]<[str]></code>.
17251727
///
17261728
/// This will drop any excess capacity.
17271729
///
1728-
/// [`str`]: prim@str
1730+
/// [str]: prim@str "str"
17291731
///
17301732
/// # Examples
17311733
///
@@ -1795,8 +1797,8 @@ impl FromUtf8Error {
17951797
/// an analogue to `FromUtf8Error`. See its documentation for more details
17961798
/// on using it.
17971799
///
1798-
/// [`std::str`]: core::str
1799-
/// [`&str`]: prim@str
1800+
/// [`std::str`]: core::str "std::str"
1801+
/// [`&str`]: prim@str "&str"
18001802
///
18011803
/// # Examples
18021804
///
@@ -2319,7 +2321,7 @@ impl ops::DerefMut for String {
23192321
///
23202322
/// This alias exists for backwards compatibility, and may be eventually deprecated.
23212323
///
2322-
/// [`Infallible`]: core::convert::Infallible
2324+
/// [`Infallible`]: core::convert::Infallible "convert::Infallible"
23232325
#[stable(feature = "str_parse_error", since = "1.5.0")]
23242326
pub type ParseError = core::convert::Infallible;
23252327

@@ -2606,7 +2608,7 @@ impl<'a> From<&'a str> for Cow<'a, str> {
26062608
/// assert_eq!(Cow::from("eggplant"), Cow::Borrowed("eggplant"));
26072609
/// ```
26082610
///
2609-
/// [`Borrowed`]: crate::borrow::Cow::Borrowed
2611+
/// [`Borrowed`]: crate::borrow::Cow::Borrowed "borrow::Cow::Borrowed"
26102612
#[inline]
26112613
fn from(s: &'a str) -> Cow<'a, str> {
26122614
Cow::Borrowed(s)
@@ -2629,7 +2631,7 @@ impl<'a> From<String> for Cow<'a, str> {
26292631
/// assert_eq!(Cow::from(s), Cow::<'static, str>::Owned(s2));
26302632
/// ```
26312633
///
2632-
/// [`Owned`]: crate::borrow::Cow::Owned
2634+
/// [`Owned`]: crate::borrow::Cow::Owned "borrow::Cow::Owned"
26332635
#[inline]
26342636
fn from(s: String) -> Cow<'a, str> {
26352637
Cow::Owned(s)
@@ -2651,7 +2653,7 @@ impl<'a> From<&'a String> for Cow<'a, str> {
26512653
/// assert_eq!(Cow::from(&s), Cow::Borrowed("eggplant"));
26522654
/// ```
26532655
///
2654-
/// [`Borrowed`]: crate::borrow::Cow::Borrowed
2656+
/// [`Borrowed`]: crate::borrow::Cow::Borrowed "borrow::Cow::Borrowed"
26552657
#[inline]
26562658
fn from(s: &'a String) -> Cow<'a, str> {
26572659
Cow::Borrowed(s.as_str())

‎library/alloc/src/sync.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ macro_rules! acquire {
9999
/// first: after all, isn't the point of `Arc<T>` thread safety? The key is
100100
/// this: `Arc<T>` makes it thread safe to have multiple ownership of the same
101101
/// data, but it doesn't add thread safety to its data. Consider
102-
/// `Arc<`[`RefCell<T>`]`>`. [`RefCell<T>`] isn't [`Sync`], and if `Arc<T>` was always
103-
/// [`Send`], `Arc<`[`RefCell<T>`]`>` would be as well. But then we'd have a problem:
102+
/// <code>Arc<[RefCell\<T>]></code>. [`RefCell<T>`] isn't [`Sync`], and if `Arc<T>` was always
103+
/// [`Send`], <code>Arc<[RefCell\<T>]></code> would be as well. But then we'd have a problem:
104104
/// [`RefCell<T>`] is not thread safe; it keeps track of the borrowing count using
105105
/// non-atomic operations.
106106
///
@@ -176,6 +176,7 @@ macro_rules! acquire {
176176
/// [deref]: core::ops::Deref
177177
/// [downgrade]: Arc::downgrade
178178
/// [upgrade]: Weak::upgrade
179+
/// [RefCell\<T>]: core::cell::RefCell
179180
/// [`RefCell<T>`]: core::cell::RefCell
180181
/// [`std::sync`]: ../../std/sync/index.html
181182
/// [`Arc::clone(&from)`]: Arc::clone
@@ -206,7 +207,7 @@ macro_rules! acquire {
206207
///
207208
/// Sharing a mutable [`AtomicUsize`]:
208209
///
209-
/// [`AtomicUsize`]: core::sync::atomic::AtomicUsize
210+
/// [`AtomicUsize`]: core::sync::atomic::AtomicUsize "sync::atomic::AtomicUsize"
210211
///
211212
/// ```no_run
212213
/// use std::sync::Arc;
@@ -262,7 +263,7 @@ impl<T: ?Sized> Arc<T> {
262263

263264
/// `Weak` is a version of [`Arc`] that holds a non-owning reference to the
264265
/// managed allocation. The allocation is accessed by calling [`upgrade`] on the `Weak`
265-
/// pointer, which returns an [`Option`]`<`[`Arc`]`<T>>`.
266+
/// pointer, which returns an <code>[Option]<[Arc]\<T>></code>.
266267
///
267268
/// Since a `Weak` reference does not count towards ownership, it will not
268269
/// prevent the value stored in the allocation from being dropped, and `Weak` itself makes no
@@ -476,7 +477,7 @@ impl<T> Arc<T> {
476477
/// assert_eq!(*zero, 0)
477478
/// ```
478479
///
479-
/// [zeroed]: ../../std/mem/union.MaybeUninit.html#method.zeroed
480+
/// [zeroed]: mem::MaybeUninit::zeroed
480481
#[cfg(not(no_global_oom_handling))]
481482
#[unstable(feature = "new_uninit", issue = "63291")]
482483
pub fn new_zeroed() -> Arc<mem::MaybeUninit<T>> {
@@ -684,7 +685,7 @@ impl<T> Arc<[T]> {
684685
/// assert_eq!(*values, [0, 0, 0])
685686
/// ```
686687
///
687-
/// [zeroed]: ../../std/mem/union.MaybeUninit.html#method.zeroed
688+
/// [zeroed]: mem::MaybeUninit::zeroed
688689
#[cfg(not(no_global_oom_handling))]
689690
#[unstable(feature = "new_uninit", issue = "63291")]
690691
pub fn new_zeroed_slice(len: usize) -> Arc<[mem::MaybeUninit<T>]> {
@@ -712,7 +713,7 @@ impl<T> Arc<mem::MaybeUninit<T>> {
712713
/// Calling this when the content is not yet fully initialized
713714
/// causes immediate undefined behavior.
714715
///
715-
/// [`MaybeUninit::assume_init`]: ../../std/mem/union.MaybeUninit.html#method.assume_init
716+
/// [`MaybeUninit::assume_init`]: mem::MaybeUninit::assume_init
716717
///
717718
/// # Examples
718719
///
@@ -751,7 +752,7 @@ impl<T> Arc<[mem::MaybeUninit<T>]> {
751752
/// Calling this when the content is not yet fully initialized
752753
/// causes immediate undefined behavior.
753754
///
754-
/// [`MaybeUninit::assume_init`]: ../../std/mem/union.MaybeUninit.html#method.assume_init
755+
/// [`MaybeUninit::assume_init`]: mem::MaybeUninit::assume_init
755756
///
756757
/// # Examples
757758
///
@@ -1086,7 +1087,7 @@ impl<T: ?Sized> Arc<T> {
10861087
/// assert!(!Arc::ptr_eq(&five, &other_five));
10871088
/// ```
10881089
///
1089-
/// [`ptr::eq`]: core::ptr::eq
1090+
/// [`ptr::eq`]: core::ptr::eq "ptr::eq"
10901091
pub fn ptr_eq(this: &Self, other: &Self) -> bool {
10911092
this.ptr.as_ptr() == other.ptr.as_ptr()
10921093
}
@@ -1714,7 +1715,7 @@ impl<T: ?Sized> Weak<T> {
17141715
/// // assert_eq!("hello", unsafe { &*weak.as_ptr() });
17151716
/// ```
17161717
///
1717-
/// [`null`]: core::ptr::null
1718+
/// [`null`]: core::ptr::null "ptr::null"
17181719
#[stable(feature = "weak_into_raw", since = "1.45.0")]
17191720
pub fn as_ptr(&self) -> *const T {
17201721
let ptr: *mut ArcInner<T> = NonNull::as_ptr(self.ptr);
@@ -1806,7 +1807,6 @@ impl<T: ?Sized> Weak<T> {
18061807
/// [`new`]: Weak::new
18071808
/// [`into_raw`]: Weak::into_raw
18081809
/// [`upgrade`]: Weak::upgrade
1809-
/// [`forget`]: std::mem::forget
18101810
#[stable(feature = "weak_into_raw", since = "1.45.0")]
18111811
pub unsafe fn from_raw(ptr: *const T) -> Self {
18121812
// See Weak::as_ptr for context on how the input pointer is derived.
@@ -1982,7 +1982,7 @@ impl<T: ?Sized> Weak<T> {
19821982
/// assert!(!first.ptr_eq(&third));
19831983
/// ```
19841984
///
1985-
/// [`ptr::eq`]: core::ptr::eq
1985+
/// [`ptr::eq`]: core::ptr::eq "ptr::eq"
19861986
#[inline]
19871987
#[stable(feature = "weak_ptr_eq", since = "1.39.0")]
19881988
pub fn ptr_eq(&self, other: &Self) -> bool {

0 commit comments

Comments
 (0)
Please sign in to comment.