Skip to content

Commit 5ad79a2

Browse files
authored
Rollup merge of rust-lang#82950 - mockersf:slice-intra-doc-link, r=jyn514
convert slice doc link to intra-doc links Continuing where rust-lang#80189 stopped, with `core::slice`. I had an issue with two dead links in my doc when implementing `Deref<Target = [T]>` for one of my type. This means that [`binary_search_by_key`](https://doc.rust-lang.org/nightly/std/primitive.slice.html#method.binary_search_by_key) was available, but not [`sort_by_key`](https://doc.rust-lang.org/nightly/std/primitive.slice.html#method.sort_by_key) even though it was linked in it's doc (same issue with [`as_ptr`](https://doc.rust-lang.org/nightly/std/primitive.slice.html#method.as_ptr) and [`as_mut_pbr`](https://doc.rust-lang.org/nightly/std/primitive.slice.html#method.as_mut_ptr)). It becomes available if I implement `DerefMut`, as it needs an `&mut self`. <details> <summary>Code that will have dead links in its doc</summary> ```rust pub struct A; pub struct B; impl std::ops::Deref for B{ type Target = [A]; fn deref(&self) -> &Self::Target { &A } } ``` </details> I removed the link to `sort_by_key` from `binary_search_by_key` doc as I didn't find a nice way to have a live link: - `binary_search_by_key` is in `core` - `sort_by_key` is in `alloc` - intra-doc link `slice::sort_by_key` doesn't work, as `alloc` is not available when `core` is being build (the warning can't be ignored: ```error[E0710]: an unknown tool name found in scoped lint: `rustdoc::broken_intra_doc_links` ```) - keeping the link as an anchor `#method.sort_by_key` meant a dead link - an absolute link would work but doesn't feel right...
2 parents 2515638 + 232b9f1 commit 5ad79a2

File tree

3 files changed

+64
-63
lines changed

3 files changed

+64
-63
lines changed

library/alloc/src/slice.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ impl<T> [T] {
231231
///
232232
/// When applicable, unstable sorting is preferred because it is generally faster than stable
233233
/// sorting and it doesn't allocate auxiliary memory.
234-
/// See [`sort_unstable`](#method.sort_unstable).
234+
/// See [`sort_unstable`](slice::sort_unstable).
235235
///
236236
/// # Current implementation
237237
///
@@ -282,7 +282,7 @@ impl<T> [T] {
282282
///
283283
/// When applicable, unstable sorting is preferred because it is generally faster than stable
284284
/// sorting and it doesn't allocate auxiliary memory.
285-
/// See [`sort_unstable_by`](#method.sort_unstable_by).
285+
/// See [`sort_unstable_by`](slice::sort_unstable_by).
286286
///
287287
/// # Current implementation
288288
///
@@ -320,12 +320,12 @@ impl<T> [T] {
320320
/// worst-case, where the key function is *O*(*m*).
321321
///
322322
/// For expensive key functions (e.g. functions that are not simple property accesses or
323-
/// basic operations), [`sort_by_cached_key`](#method.sort_by_cached_key) is likely to be
323+
/// basic operations), [`sort_by_cached_key`](slice::sort_by_cached_key) is likely to be
324324
/// significantly faster, as it does not recompute element keys.
325325
///
326326
/// When applicable, unstable sorting is preferred because it is generally faster than stable
327327
/// sorting and it doesn't allocate auxiliary memory.
328-
/// See [`sort_unstable_by_key`](#method.sort_unstable_by_key).
328+
/// See [`sort_unstable_by_key`](slice::sort_unstable_by_key).
329329
///
330330
/// # Current implementation
331331
///
@@ -363,7 +363,7 @@ impl<T> [T] {
363363
/// worst-case, where the key function is *O*(*m*).
364364
///
365365
/// For simple key functions (e.g., functions that are property accesses or
366-
/// basic operations), [`sort_by_key`](#method.sort_by_key) is likely to be
366+
/// basic operations), [`sort_by_key`](slice::sort_by_key) is likely to be
367367
/// faster.
368368
///
369369
/// # Current implementation

library/core/src/slice/mod.rs

+59-53
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ impl<T> [T] {
308308
/// Returns a mutable reference to an element or subslice depending on the
309309
/// type of index (see [`get`]) or `None` if the index is out of bounds.
310310
///
311-
/// [`get`]: #method.get
311+
/// [`get`]: slice::get
312312
///
313313
/// # Examples
314314
///
@@ -339,7 +339,7 @@ impl<T> [T] {
339339
/// Calling this method with an out-of-bounds index is *[undefined behavior]*
340340
/// even if the resulting reference is not used.
341341
///
342-
/// [`get`]: #method.get
342+
/// [`get`]: slice::get
343343
/// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
344344
///
345345
/// # Examples
@@ -373,7 +373,7 @@ impl<T> [T] {
373373
/// Calling this method with an out-of-bounds index is *[undefined behavior]*
374374
/// even if the resulting reference is not used.
375375
///
376-
/// [`get_mut`]: #method.get_mut
376+
/// [`get_mut`]: slice::get_mut
377377
/// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
378378
///
379379
/// # Examples
@@ -424,7 +424,7 @@ impl<T> [T] {
424424
/// }
425425
/// ```
426426
///
427-
/// [`as_mut_ptr`]: #method.as_mut_ptr
427+
/// [`as_mut_ptr`]: slice::as_mut_ptr
428428
#[stable(feature = "rust1", since = "1.0.0")]
429429
#[rustc_const_stable(feature = "const_slice_as_ptr", since = "1.32.0")]
430430
#[inline]
@@ -487,7 +487,7 @@ impl<T> [T] {
487487
/// assert!(!a.as_ptr_range().contains(&y));
488488
/// ```
489489
///
490-
/// [`as_ptr`]: #method.as_ptr
490+
/// [`as_ptr`]: slice::as_ptr
491491
#[stable(feature = "slice_ptr_range", since = "1.48.0")]
492492
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
493493
#[inline]
@@ -529,7 +529,7 @@ impl<T> [T] {
529529
/// use two pointers to refer to a range of elements in memory, as is
530530
/// common in C++.
531531
///
532-
/// [`as_mut_ptr`]: #method.as_mut_ptr
532+
/// [`as_mut_ptr`]: slice::as_mut_ptr
533533
#[stable(feature = "slice_ptr_range", since = "1.48.0")]
534534
#[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
535535
#[inline]
@@ -780,8 +780,8 @@ impl<T> [T] {
780780
/// assert!(iter.next().is_none());
781781
/// ```
782782
///
783-
/// [`chunks_exact`]: #method.chunks_exact
784-
/// [`rchunks`]: #method.rchunks
783+
/// [`chunks_exact`]: slice::chunks_exact
784+
/// [`rchunks`]: slice::rchunks
785785
#[stable(feature = "rust1", since = "1.0.0")]
786786
#[inline]
787787
pub fn chunks(&self, chunk_size: usize) -> Chunks<'_, T> {
@@ -818,8 +818,8 @@ impl<T> [T] {
818818
/// assert_eq!(v, &[1, 1, 2, 2, 3]);
819819
/// ```
820820
///
821-
/// [`chunks_exact_mut`]: #method.chunks_exact_mut
822-
/// [`rchunks_mut`]: #method.rchunks_mut
821+
/// [`chunks_exact_mut`]: slice::chunks_exact_mut
822+
/// [`rchunks_mut`]: slice::rchunks_mut
823823
#[stable(feature = "rust1", since = "1.0.0")]
824824
#[inline]
825825
pub fn chunks_mut(&mut self, chunk_size: usize) -> ChunksMut<'_, T> {
@@ -855,8 +855,8 @@ impl<T> [T] {
855855
/// assert_eq!(iter.remainder(), &['m']);
856856
/// ```
857857
///
858-
/// [`chunks`]: #method.chunks
859-
/// [`rchunks_exact`]: #method.rchunks_exact
858+
/// [`chunks`]: slice::chunks
859+
/// [`rchunks_exact`]: slice::rchunks_exact
860860
#[stable(feature = "chunks_exact", since = "1.31.0")]
861861
#[inline]
862862
pub fn chunks_exact(&self, chunk_size: usize) -> ChunksExact<'_, T> {
@@ -897,8 +897,8 @@ impl<T> [T] {
897897
/// assert_eq!(v, &[1, 1, 2, 2, 0]);
898898
/// ```
899899
///
900-
/// [`chunks_mut`]: #method.chunks_mut
901-
/// [`rchunks_exact_mut`]: #method.rchunks_exact_mut
900+
/// [`chunks_mut`]: slice::chunks_mut
901+
/// [`rchunks_exact_mut`]: slice::rchunks_exact_mut
902902
#[stable(feature = "chunks_exact", since = "1.31.0")]
903903
#[inline]
904904
pub fn chunks_exact_mut(&mut self, chunk_size: usize) -> ChunksExactMut<'_, T> {
@@ -1032,7 +1032,7 @@ impl<T> [T] {
10321032
/// assert_eq!(iter.remainder(), &['m']);
10331033
/// ```
10341034
///
1035-
/// [`chunks_exact`]: #method.chunks_exact
1035+
/// [`chunks_exact`]: slice::chunks_exact
10361036
#[unstable(feature = "array_chunks", issue = "74985")]
10371037
#[inline]
10381038
pub fn array_chunks<const N: usize>(&self) -> ArrayChunks<'_, T, N> {
@@ -1182,7 +1182,7 @@ impl<T> [T] {
11821182
/// assert_eq!(v, &[1, 1, 2, 2, 0]);
11831183
/// ```
11841184
///
1185-
/// [`chunks_exact_mut`]: #method.chunks_exact_mut
1185+
/// [`chunks_exact_mut`]: slice::chunks_exact_mut
11861186
#[unstable(feature = "array_chunks", issue = "74985")]
11871187
#[inline]
11881188
pub fn array_chunks_mut<const N: usize>(&mut self) -> ArrayChunksMut<'_, T, N> {
@@ -1214,7 +1214,7 @@ impl<T> [T] {
12141214
/// assert!(iter.next().is_none());
12151215
/// ```
12161216
///
1217-
/// [`windows`]: #method.windows
1217+
/// [`windows`]: slice::windows
12181218
#[unstable(feature = "array_windows", issue = "75027")]
12191219
#[inline]
12201220
pub fn array_windows<const N: usize>(&self) -> ArrayWindows<'_, T, N> {
@@ -1247,8 +1247,8 @@ impl<T> [T] {
12471247
/// assert!(iter.next().is_none());
12481248
/// ```
12491249
///
1250-
/// [`rchunks_exact`]: #method.rchunks_exact
1251-
/// [`chunks`]: #method.chunks
1250+
/// [`rchunks_exact`]: slice::rchunks_exact
1251+
/// [`chunks`]: slice::chunks
12521252
#[stable(feature = "rchunks", since = "1.31.0")]
12531253
#[inline]
12541254
pub fn rchunks(&self, chunk_size: usize) -> RChunks<'_, T> {
@@ -1285,8 +1285,8 @@ impl<T> [T] {
12851285
/// assert_eq!(v, &[3, 2, 2, 1, 1]);
12861286
/// ```
12871287
///
1288-
/// [`rchunks_exact_mut`]: #method.rchunks_exact_mut
1289-
/// [`chunks_mut`]: #method.chunks_mut
1288+
/// [`rchunks_exact_mut`]: slice::rchunks_exact_mut
1289+
/// [`chunks_mut`]: slice::chunks_mut
12901290
#[stable(feature = "rchunks", since = "1.31.0")]
12911291
#[inline]
12921292
pub fn rchunks_mut(&mut self, chunk_size: usize) -> RChunksMut<'_, T> {
@@ -1323,9 +1323,9 @@ impl<T> [T] {
13231323
/// assert_eq!(iter.remainder(), &['l']);
13241324
/// ```
13251325
///
1326-
/// [`chunks`]: #method.chunks
1327-
/// [`rchunks`]: #method.rchunks
1328-
/// [`chunks_exact`]: #method.chunks_exact
1326+
/// [`chunks`]: slice::chunks
1327+
/// [`rchunks`]: slice::rchunks
1328+
/// [`chunks_exact`]: slice::chunks_exact
13291329
#[stable(feature = "rchunks", since = "1.31.0")]
13301330
#[inline]
13311331
pub fn rchunks_exact(&self, chunk_size: usize) -> RChunksExact<'_, T> {
@@ -1366,9 +1366,9 @@ impl<T> [T] {
13661366
/// assert_eq!(v, &[0, 2, 2, 1, 1]);
13671367
/// ```
13681368
///
1369-
/// [`chunks_mut`]: #method.chunks_mut
1370-
/// [`rchunks_mut`]: #method.rchunks_mut
1371-
/// [`chunks_exact_mut`]: #method.chunks_exact_mut
1369+
/// [`chunks_mut`]: slice::chunks_mut
1370+
/// [`rchunks_mut`]: slice::rchunks_mut
1371+
/// [`chunks_exact_mut`]: slice::chunks_exact_mut
13721372
#[stable(feature = "rchunks", since = "1.31.0")]
13731373
#[inline]
13741374
pub fn rchunks_exact_mut(&mut self, chunk_size: usize) -> RChunksExactMut<'_, T> {
@@ -1552,7 +1552,7 @@ impl<T> [T] {
15521552
/// even if the resulting reference is not used. The caller has to ensure that
15531553
/// `0 <= mid <= self.len()`.
15541554
///
1555-
/// [`split_at`]: #method.split_at
1555+
/// [`split_at`]: slice::split_at
15561556
/// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
15571557
///
15581558
/// # Examples
@@ -1601,7 +1601,7 @@ impl<T> [T] {
16011601
/// even if the resulting reference is not used. The caller has to ensure that
16021602
/// `0 <= mid <= self.len()`.
16031603
///
1604-
/// [`split_at_mut`]: #method.split_at_mut
1604+
/// [`split_at_mut`]: slice::split_at_mut
16051605
/// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
16061606
///
16071607
/// # Examples
@@ -2103,9 +2103,9 @@ impl<T> [T] {
21032103
///
21042104
/// See also [`binary_search_by`], [`binary_search_by_key`], and [`partition_point`].
21052105
///
2106-
/// [`binary_search_by`]: #method.binary_search_by
2107-
/// [`binary_search_by_key`]: #method.binary_search_by_key
2108-
/// [`partition_point`]: #method.partition_point
2106+
/// [`binary_search_by`]: slice::binary_search_by
2107+
/// [`binary_search_by_key`]: slice::binary_search_by_key
2108+
/// [`partition_point`]: slice::partition_point
21092109
///
21102110
/// # Examples
21112111
///
@@ -2156,9 +2156,9 @@ impl<T> [T] {
21562156
///
21572157
/// See also [`binary_search`], [`binary_search_by_key`], and [`partition_point`].
21582158
///
2159-
/// [`binary_search`]: #method.binary_search
2160-
/// [`binary_search_by_key`]: #method.binary_search_by_key
2161-
/// [`partition_point`]: #method.partition_point
2159+
/// [`binary_search`]: slice::binary_search
2160+
/// [`binary_search_by_key`]: slice::binary_search_by_key
2161+
/// [`partition_point`]: slice::partition_point
21622162
///
21632163
/// # Examples
21642164
///
@@ -2225,10 +2225,10 @@ impl<T> [T] {
22252225
///
22262226
/// See also [`binary_search`], [`binary_search_by`], and [`partition_point`].
22272227
///
2228-
/// [`sort_by_key`]: #method.sort_by_key
2229-
/// [`binary_search`]: #method.binary_search
2230-
/// [`binary_search_by`]: #method.binary_search_by
2231-
/// [`partition_point`]: #method.partition_point
2228+
/// [`sort_by_key`]: slice::sort_by_key
2229+
/// [`binary_search`]: slice::binary_search
2230+
/// [`binary_search_by`]: slice::binary_search_by
2231+
/// [`partition_point`]: slice::partition_point
22322232
///
22332233
/// # Examples
22342234
///
@@ -2248,6 +2248,12 @@ impl<T> [T] {
22482248
/// let r = s.binary_search_by_key(&1, |&(a, b)| b);
22492249
/// assert!(match r { Ok(1..=4) => true, _ => false, });
22502250
/// ```
2251+
// Lint rustdoc::broken_intra_doc_links is allowed as `slice::sort_by_key` is
2252+
// in crate `alloc`, and as such doesn't exists yet when building `core`.
2253+
// links to downstream crate: #74481. Since primitives are only documented in
2254+
// libstd (#73423), this never leads to broken links in practice.
2255+
#[cfg_attr(not(bootstrap), allow(rustdoc::broken_intra_doc_links))]
2256+
#[cfg_attr(bootstrap, allow(broken_intra_doc_links))]
22512257
#[stable(feature = "slice_binary_search_by_key", since = "1.10.0")]
22522258
#[inline]
22532259
pub fn binary_search_by_key<'a, B, F>(&'a self, b: &B, mut f: F) -> Result<usize, usize>
@@ -2446,7 +2452,7 @@ impl<T> [T] {
24462452
/// The current algorithm is based on the quickselect portion of the same quicksort algorithm
24472453
/// used for [`sort_unstable`].
24482454
///
2449-
/// [`sort_unstable`]: #method.sort_unstable
2455+
/// [`sort_unstable`]: slice::sort_unstable
24502456
///
24512457
/// # Panics
24522458
///
@@ -2494,7 +2500,7 @@ impl<T> [T] {
24942500
/// The current algorithm is based on the quickselect portion of the same quicksort algorithm
24952501
/// used for [`sort_unstable`].
24962502
///
2497-
/// [`sort_unstable`]: #method.sort_unstable
2503+
/// [`sort_unstable`]: slice::sort_unstable
24982504
///
24992505
/// # Panics
25002506
///
@@ -2546,7 +2552,7 @@ impl<T> [T] {
25462552
/// The current algorithm is based on the quickselect portion of the same quicksort algorithm
25472553
/// used for [`sort_unstable`].
25482554
///
2549-
/// [`sort_unstable`]: #method.sort_unstable
2555+
/// [`sort_unstable`]: slice::sort_unstable
25502556
///
25512557
/// # Panics
25522558
///
@@ -2883,7 +2889,7 @@ impl<T> [T] {
28832889
/// trait to generate values, you can pass [`Default::default`] as the
28842890
/// argument.
28852891
///
2886-
/// [`fill`]: #method.fill
2892+
/// [`fill`]: slice::fill
28872893
///
28882894
/// # Examples
28892895
///
@@ -2956,8 +2962,8 @@ impl<T> [T] {
29562962
/// assert_eq!(slice, [4, 5, 3, 4, 5]);
29572963
/// ```
29582964
///
2959-
/// [`copy_from_slice`]: #method.copy_from_slice
2960-
/// [`split_at_mut`]: #method.split_at_mut
2965+
/// [`copy_from_slice`]: slice::copy_from_slice
2966+
/// [`split_at_mut`]: slice::split_at_mut
29612967
#[stable(feature = "clone_from_slice", since = "1.7.0")]
29622968
pub fn clone_from_slice(&mut self, src: &[T])
29632969
where
@@ -3018,8 +3024,8 @@ impl<T> [T] {
30183024
/// assert_eq!(slice, [4, 5, 3, 4, 5]);
30193025
/// ```
30203026
///
3021-
/// [`clone_from_slice`]: #method.clone_from_slice
3022-
/// [`split_at_mut`]: #method.split_at_mut
3027+
/// [`clone_from_slice`]: slice::clone_from_slice
3028+
/// [`split_at_mut`]: slice::split_at_mut
30233029
#[doc(alias = "memcpy")]
30243030
#[stable(feature = "copy_from_slice", since = "1.9.0")]
30253031
pub fn copy_from_slice(&mut self, src: &[T])
@@ -3136,7 +3142,7 @@ impl<T> [T] {
31363142
/// assert_eq!(slice, [4, 5, 3, 1, 2]);
31373143
/// ```
31383144
///
3139-
/// [`split_at_mut`]: #method.split_at_mut
3145+
/// [`split_at_mut`]: slice::split_at_mut
31403146
#[stable(feature = "swap_with_slice", since = "1.27.0")]
31413147
pub fn swap_with_slice(&mut self, other: &mut [T]) {
31423148
assert!(self.len() == other.len(), "destination and source slices have different lengths");
@@ -3380,7 +3386,7 @@ impl<T> [T] {
33803386
/// function to determine the ordering of two elements. Apart from that, it's equivalent to
33813387
/// [`is_sorted`]; see its documentation for more information.
33823388
///
3383-
/// [`is_sorted`]: #method.is_sorted
3389+
/// [`is_sorted`]: slice::is_sorted
33843390
#[unstable(feature = "is_sorted", reason = "new API", issue = "53485")]
33853391
pub fn is_sorted_by<F>(&self, mut compare: F) -> bool
33863392
where
@@ -3395,7 +3401,7 @@ impl<T> [T] {
33953401
/// elements, as determined by `f`. Apart from that, it's equivalent to [`is_sorted`]; see its
33963402
/// documentation for more information.
33973403
///
3398-
/// [`is_sorted`]: #method.is_sorted
3404+
/// [`is_sorted`]: slice::is_sorted
33993405
///
34003406
/// # Examples
34013407
///
@@ -3429,9 +3435,9 @@ impl<T> [T] {
34293435
///
34303436
/// See also [`binary_search`], [`binary_search_by`], and [`binary_search_by_key`].
34313437
///
3432-
/// [`binary_search`]: #method.binary_search
3433-
/// [`binary_search_by`]: #method.binary_search_by
3434-
/// [`binary_search_by_key`]: #method.binary_search_by_key
3438+
/// [`binary_search`]: slice::binary_search
3439+
/// [`binary_search_by`]: slice::binary_search_by
3440+
/// [`binary_search_by_key`]: slice::binary_search_by_key
34353441
///
34363442
/// # Examples
34373443
///

src/tools/linkchecker/main.rs

-5
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ use crate::Redirect::*;
3333
// are cases where that does not work
3434
// [(generated_documentation_page, &[broken_links])]
3535
const LINKCHECK_EXCEPTIONS: &[(&str, &[&str])] = &[
36-
// These are methods on slice, and `Self` does not work on primitive impls
37-
// in intra-doc links (primitive impls are weird)
38-
// https://github.com/rust-lang/rust/issues/62834 is necessary to be
39-
// able to link to slices
40-
("std/io/struct.IoSlice.html", &["#method.as_mut_ptr", "#method.sort_by_key"]),
4136
// These try to link to std::collections, but are defined in alloc
4237
// https://github.com/rust-lang/rust/issues/74481
4338
("std/collections/btree_map/struct.BTreeMap.html", &["#insert-and-complex-keys"]),

0 commit comments

Comments
 (0)