Skip to content

Commit b7dc6d5

Browse files
authored
Rollup merge of rust-lang#76867 - poliorcetics:intra-doc-core-iter, r=jyn514
Use intra-doc links in core/src/iter when possible Helps with rust-lang#75080. I also updated lots of links to use `fn()` instead of `fn` when possible. @rustbot modify labels: T-doc A-intra-doc-links r? @jyn514
2 parents 62ddc9b + 08b85a6 commit b7dc6d5

File tree

7 files changed

+93
-130
lines changed

7 files changed

+93
-130
lines changed

library/core/src/iter/sources.rs

+29-47
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ use super::{FusedIterator, TrustedLen};
55

66
/// An iterator that repeats an element endlessly.
77
///
8-
/// This `struct` is created by the [`repeat`] function. See its documentation for more.
9-
///
10-
/// [`repeat`]: fn.repeat.html
8+
/// This `struct` is created by the [`repeat()`] function. See its documentation for more.
119
#[derive(Clone, Debug)]
1210
#[stable(feature = "rust1", since = "1.0.0")]
1311
pub struct Repeat<A> {
@@ -47,15 +45,11 @@ unsafe impl<A: Clone> TrustedLen for Repeat<A> {}
4745
/// The `repeat()` function repeats a single value over and over again.
4846
///
4947
/// Infinite iterators like `repeat()` are often used with adapters like
50-
/// [`take`], in order to make them finite.
51-
///
52-
/// [`take`]: trait.Iterator.html#method.take
48+
/// [`Iterator::take()`], in order to make them finite.
5349
///
5450
/// If the element type of the iterator you need does not implement `Clone`,
5551
/// or if you do not want to keep the repeated element in memory, you can
56-
/// instead use the [`repeat_with`] function.
57-
///
58-
/// [`repeat_with`]: fn.repeat_with.html
52+
/// instead use the [`repeat_with()`] function.
5953
///
6054
/// # Examples
6155
///
@@ -77,7 +71,7 @@ unsafe impl<A: Clone> TrustedLen for Repeat<A> {}
7771
/// assert_eq!(Some(4), fours.next());
7872
/// ```
7973
///
80-
/// Going finite with [`take`]:
74+
/// Going finite with [`Iterator::take()`]:
8175
///
8276
/// ```
8377
/// use std::iter;
@@ -102,10 +96,8 @@ pub fn repeat<T: Clone>(elt: T) -> Repeat<T> {
10296
/// An iterator that repeats elements of type `A` endlessly by
10397
/// applying the provided closure `F: FnMut() -> A`.
10498
///
105-
/// This `struct` is created by the [`repeat_with`] function.
99+
/// This `struct` is created by the [`repeat_with()`] function.
106100
/// See its documentation for more.
107-
///
108-
/// [`repeat_with`]: fn.repeat_with.html
109101
#[derive(Copy, Clone, Debug)]
110102
#[stable(feature = "iterator_repeat_with", since = "1.28.0")]
111103
pub struct RepeatWith<F> {
@@ -139,20 +131,18 @@ unsafe impl<A, F: FnMut() -> A> TrustedLen for RepeatWith<F> {}
139131
/// The `repeat_with()` function calls the repeater over and over again.
140132
///
141133
/// Infinite iterators like `repeat_with()` are often used with adapters like
142-
/// [`take`], in order to make them finite.
143-
///
144-
/// [`take`]: trait.Iterator.html#method.take
134+
/// [`Iterator::take()`], in order to make them finite.
145135
///
146-
/// If the element type of the iterator you need implements `Clone`, and
136+
/// If the element type of the iterator you need implements [`Clone`], and
147137
/// it is OK to keep the source element in memory, you should instead use
148-
/// the [`repeat`] function.
149-
///
150-
/// [`repeat`]: fn.repeat.html
138+
/// the [`repeat()`] function.
151139
///
152-
/// An iterator produced by `repeat_with()` is not a `DoubleEndedIterator`.
153-
/// If you need `repeat_with()` to return a `DoubleEndedIterator`,
140+
/// An iterator produced by `repeat_with()` is not a [`DoubleEndedIterator`].
141+
/// If you need `repeat_with()` to return a [`DoubleEndedIterator`],
154142
/// please open a GitHub issue explaining your use case.
155143
///
144+
/// [`DoubleEndedIterator`]: crate::iter::DoubleEndedIterator
145+
///
156146
/// # Examples
157147
///
158148
/// Basic usage:
@@ -201,9 +191,7 @@ pub fn repeat_with<A, F: FnMut() -> A>(repeater: F) -> RepeatWith<F> {
201191

202192
/// An iterator that yields nothing.
203193
///
204-
/// This `struct` is created by the [`empty`] function. See its documentation for more.
205-
///
206-
/// [`empty`]: fn.empty.html
194+
/// This `struct` is created by the [`empty()`] function. See its documentation for more.
207195
#[stable(feature = "iter_empty", since = "1.2.0")]
208196
pub struct Empty<T>(marker::PhantomData<T>);
209197

@@ -292,9 +280,7 @@ pub const fn empty<T>() -> Empty<T> {
292280

293281
/// An iterator that yields an element exactly once.
294282
///
295-
/// This `struct` is created by the [`once`] function. See its documentation for more.
296-
///
297-
/// [`once`]: fn.once.html
283+
/// This `struct` is created by the [`once()`] function. See its documentation for more.
298284
#[derive(Clone, Debug)]
299285
#[stable(feature = "iter_once", since = "1.2.0")]
300286
pub struct Once<T> {
@@ -336,12 +322,12 @@ impl<T> FusedIterator for Once<T> {}
336322

337323
/// Creates an iterator that yields an element exactly once.
338324
///
339-
/// This is commonly used to adapt a single value into a [`chain`] of other
325+
/// This is commonly used to adapt a single value into a [`chain()`] of other
340326
/// kinds of iteration. Maybe you have an iterator that covers almost
341327
/// everything, but you need an extra special case. Maybe you have a function
342328
/// which works on iterators, but you only need to process one value.
343329
///
344-
/// [`chain`]: trait.Iterator.html#method.chain
330+
/// [`chain()`]: Iterator::chain
345331
///
346332
/// # Examples
347333
///
@@ -393,10 +379,8 @@ pub fn once<T>(value: T) -> Once<T> {
393379
/// An iterator that yields a single element of type `A` by
394380
/// applying the provided closure `F: FnOnce() -> A`.
395381
///
396-
/// This `struct` is created by the [`once_with`] function.
382+
/// This `struct` is created by the [`once_with()`] function.
397383
/// See its documentation for more.
398-
///
399-
/// [`once_with`]: fn.once_with.html
400384
#[derive(Clone, Debug)]
401385
#[stable(feature = "iter_once_with", since = "1.43.0")]
402386
pub struct OnceWith<F> {
@@ -442,15 +426,14 @@ unsafe impl<A, F: FnOnce() -> A> TrustedLen for OnceWith<F> {}
442426
/// Creates an iterator that lazily generates a value exactly once by invoking
443427
/// the provided closure.
444428
///
445-
/// This is commonly used to adapt a single value generator into a [`chain`] of
429+
/// This is commonly used to adapt a single value generator into a [`chain()`] of
446430
/// other kinds of iteration. Maybe you have an iterator that covers almost
447431
/// everything, but you need an extra special case. Maybe you have a function
448432
/// which works on iterators, but you only need to process one value.
449433
///
450-
/// Unlike [`once`], this function will lazily generate the value on request.
434+
/// Unlike [`once()`], this function will lazily generate the value on request.
451435
///
452-
/// [`once`]: fn.once.html
453-
/// [`chain`]: trait.Iterator.html#method.chain
436+
/// [`chain()`]: Iterator::chain
454437
///
455438
/// # Examples
456439
///
@@ -505,17 +488,16 @@ pub fn once_with<A, F: FnOnce() -> A>(gen: F) -> OnceWith<F> {
505488
///
506489
/// This allows creating a custom iterator with any behavior
507490
/// without using the more verbose syntax of creating a dedicated type
508-
/// and implementing the `Iterator` trait for it.
491+
/// and implementing the [`Iterator`] trait for it.
509492
///
510493
/// Note that the `FromFn` iterator doesn’t make assumptions about the behavior of the closure,
511494
/// and therefore conservatively does not implement [`FusedIterator`],
512-
/// or override [`Iterator::size_hint`] from its default `(0, None)`.
513-
///
514-
/// [`FusedIterator`]: trait.FusedIterator.html
515-
/// [`Iterator::size_hint`]: trait.Iterator.html#method.size_hint
495+
/// or override [`Iterator::size_hint()`] from its default `(0, None)`.
516496
///
517497
/// The closure can use captures and its environment to track state across iterations. Depending on
518-
/// how the iterator is used, this may require specifying the `move` keyword on the closure.
498+
/// how the iterator is used, this may require specifying the [`move`] keyword on the closure.
499+
///
500+
/// [`move`]: ../../std/keyword.move.html
519501
///
520502
/// # Examples
521503
///
@@ -549,10 +531,10 @@ where
549531

550532
/// An iterator where each iteration calls the provided closure `F: FnMut() -> Option<T>`.
551533
///
552-
/// This `struct` is created by the [`iter::from_fn`] function.
534+
/// This `struct` is created by the [`iter::from_fn()`] function.
553535
/// See its documentation for more.
554536
///
555-
/// [`iter::from_fn`]: fn.from_fn.html
537+
/// [`iter::from_fn()`]: from_fn
556538
#[derive(Clone)]
557539
#[stable(feature = "iter_from_fn", since = "1.34.0")]
558540
pub struct FromFn<F>(F);
@@ -601,10 +583,10 @@ where
601583

602584
/// An new iterator where each successive item is computed based on the preceding one.
603585
///
604-
/// This `struct` is created by the [`successors`] function.
586+
/// This `struct` is created by the [`iter::successors()`] function.
605587
/// See its documentation for more.
606588
///
607-
/// [`successors`]: fn.successors.html
589+
/// [`iter::successors()`]: successors
608590
#[derive(Clone)]
609591
#[stable(feature = "iter_successors", since = "1.34.0")]
610592
pub struct Successors<T, F> {

library/core/src/iter/traits/accum.rs

+22-24
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@ use crate::ops::{Add, Mul};
44

55
/// Trait to represent types that can be created by summing up an iterator.
66
///
7-
/// This trait is used to implement the [`sum`] method on iterators. Types which
8-
/// implement the trait can be generated by the [`sum`] method. Like
7+
/// This trait is used to implement the [`sum()`] method on iterators. Types which
8+
/// implement the trait can be generated by the [`sum()`] method. Like
99
/// [`FromIterator`] this trait should rarely be called directly and instead
10-
/// interacted with through [`Iterator::sum`].
10+
/// interacted with through [`Iterator::sum()`].
1111
///
12-
/// [`sum`]: #tymethod.sum
13-
/// [`FromIterator`]: crate::iter::FromIterator
14-
/// [`Iterator::sum`]: crate::iter::Iterator::sum
12+
/// [`sum()`]: Sum::sum
13+
/// [`FromIterator`]: iter::FromIterator
1514
#[stable(feature = "iter_arith_traits", since = "1.12.0")]
1615
pub trait Sum<A = Self>: Sized {
1716
/// Method which takes an iterator and generates `Self` from the elements by
@@ -23,14 +22,13 @@ pub trait Sum<A = Self>: Sized {
2322
/// Trait to represent types that can be created by multiplying elements of an
2423
/// iterator.
2524
///
26-
/// This trait is used to implement the [`product`] method on iterators. Types
27-
/// which implement the trait can be generated by the [`product`] method. Like
25+
/// This trait is used to implement the [`product()`] method on iterators. Types
26+
/// which implement the trait can be generated by the [`product()`] method. Like
2827
/// [`FromIterator`] this trait should rarely be called directly and instead
29-
/// interacted with through [`Iterator::product`].
28+
/// interacted with through [`Iterator::product()`].
3029
///
31-
/// [`product`]: #tymethod.product
32-
/// [`FromIterator`]: crate::iter::FromIterator
33-
/// [`Iterator::product`]: crate::iter::Iterator::product
30+
/// [`product()`]: Product::product
31+
/// [`FromIterator`]: iter::FromIterator
3432
#[stable(feature = "iter_arith_traits", since = "1.12.0")]
3533
pub trait Product<A = Self>: Sized {
3634
/// Method which takes an iterator and generates `Self` from the elements by
@@ -120,9 +118,9 @@ impl<T, U, E> Sum<Result<U, E>> for Result<T, E>
120118
where
121119
T: Sum<U>,
122120
{
123-
/// Takes each element in the `Iterator`: if it is an `Err`, no further
124-
/// elements are taken, and the `Err` is returned. Should no `Err` occur,
125-
/// the sum of all elements is returned.
121+
/// Takes each element in the [`Iterator`]: if it is an [`Err`], no further
122+
/// elements are taken, and the [`Err`] is returned. Should no [`Err`]
123+
/// occur, the sum of all elements is returned.
126124
///
127125
/// # Examples
128126
///
@@ -150,9 +148,9 @@ impl<T, U, E> Product<Result<U, E>> for Result<T, E>
150148
where
151149
T: Product<U>,
152150
{
153-
/// Takes each element in the `Iterator`: if it is an `Err`, no further
154-
/// elements are taken, and the `Err` is returned. Should no `Err` occur,
155-
/// the product of all elements is returned.
151+
/// Takes each element in the [`Iterator`]: if it is an [`Err`], no further
152+
/// elements are taken, and the [`Err`] is returned. Should no [`Err`]
153+
/// occur, the product of all elements is returned.
156154
fn product<I>(iter: I) -> Result<T, E>
157155
where
158156
I: Iterator<Item = Result<U, E>>,
@@ -166,9 +164,9 @@ impl<T, U> Sum<Option<U>> for Option<T>
166164
where
167165
T: Sum<U>,
168166
{
169-
/// Takes each element in the `Iterator`: if it is a `None`, no further
170-
/// elements are taken, and the `None` is returned. Should no `None` occur,
171-
/// the sum of all elements is returned.
167+
/// Takes each element in the [`Iterator`]: if it is a [`None`], no further
168+
/// elements are taken, and the [`None`] is returned. Should no [`None`]
169+
/// occur, the sum of all elements is returned.
172170
///
173171
/// # Examples
174172
///
@@ -193,9 +191,9 @@ impl<T, U> Product<Option<U>> for Option<T>
193191
where
194192
T: Product<U>,
195193
{
196-
/// Takes each element in the `Iterator`: if it is a `None`, no further
197-
/// elements are taken, and the `None` is returned. Should no `None` occur,
198-
/// the product of all elements is returned.
194+
/// Takes each element in the [`Iterator`]: if it is a [`None`], no further
195+
/// elements are taken, and the [`None`] is returned. Should no [`None`]
196+
/// occur, the product of all elements is returned.
199197
fn product<I>(iter: I) -> Option<T>
200198
where
201199
I: Iterator<Item = Option<U>>,

library/core/src/iter/traits/collect.rs

+6-14
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,15 @@
1-
/// Conversion from an `Iterator`.
1+
/// Conversion from an [`Iterator`].
22
///
33
/// By implementing `FromIterator` for a type, you define how it will be
44
/// created from an iterator. This is common for types which describe a
55
/// collection of some kind.
66
///
7-
/// `FromIterator`'s [`from_iter`] is rarely called explicitly, and is instead
8-
/// used through [`Iterator`]'s [`collect`] method. See [`collect`]'s
7+
/// [`FromIterator::from_iter()`] is rarely called explicitly, and is instead
8+
/// used through [`Iterator::collect()`] method. See [`Iterator::collect()`]'s
99
/// documentation for more examples.
1010
///
11-
/// [`from_iter`]: #tymethod.from_iter
12-
/// [`Iterator`]: trait.Iterator.html
13-
/// [`collect`]: trait.Iterator.html#method.collect
14-
///
1511
/// See also: [`IntoIterator`].
1612
///
17-
/// [`IntoIterator`]: trait.IntoIterator.html
18-
///
1913
/// # Examples
2014
///
2115
/// Basic usage:
@@ -30,7 +24,7 @@
3024
/// assert_eq!(v, vec![5, 5, 5, 5, 5]);
3125
/// ```
3226
///
33-
/// Using [`collect`] to implicitly use `FromIterator`:
27+
/// Using [`Iterator::collect()`] to implicitly use `FromIterator`:
3428
///
3529
/// ```
3630
/// let five_fives = std::iter::repeat(5).take(5);
@@ -119,7 +113,7 @@ pub trait FromIterator<A>: Sized {
119113
fn from_iter<T: IntoIterator<Item = A>>(iter: T) -> Self;
120114
}
121115

122-
/// Conversion into an `Iterator`.
116+
/// Conversion into an [`Iterator`].
123117
///
124118
/// By implementing `IntoIterator` for a type, you define how it will be
125119
/// converted to an iterator. This is common for types which describe a
@@ -130,8 +124,6 @@ pub trait FromIterator<A>: Sized {
130124
///
131125
/// See also: [`FromIterator`].
132126
///
133-
/// [`FromIterator`]: trait.FromIterator.html
134-
///
135127
/// # Examples
136128
///
137129
/// Basic usage:
@@ -326,7 +318,7 @@ pub trait Extend<A> {
326318
/// As this is the only required method for this trait, the [trait-level] docs
327319
/// contain more details.
328320
///
329-
/// [trait-level]: trait.Extend.html
321+
/// [trait-level]: Extend
330322
///
331323
/// # Examples
332324
///

0 commit comments

Comments
 (0)