Skip to content

Commit 5e3123b

Browse files
committed
auto merge of #10533 : tautologico/rust/fixdocs, r=huonw
This fixes a number of bugs in the doc comments for a bunch of functions in libstd/iter.rs, mostly updating to use unwrap() instead of get() on options. Also fixes the docs for advance() (trait Iterator) which was not making sense, though if it is not useful anymore maybe it should be removed.
2 parents b4197ae + 1f27512 commit 5e3123b

File tree

1 file changed

+31
-34
lines changed

1 file changed

+31
-34
lines changed

src/libstd/iter.rs

+31-34
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ pub trait Iterator<A> {
115115
/// let a = [0];
116116
/// let b = [1];
117117
/// let mut it = a.iter().chain(b.iter());
118-
/// assert_eq!(it.next().get(), &0);
119-
/// assert_eq!(it.next().get(), &1);
118+
/// assert_eq!(it.next().unwrap(), &0);
119+
/// assert_eq!(it.next().unwrap(), &1);
120120
/// assert!(it.next().is_none());
121121
/// ```
122122
#[inline]
@@ -135,7 +135,7 @@ pub trait Iterator<A> {
135135
/// let a = [0];
136136
/// let b = [1];
137137
/// let mut it = a.iter().zip(b.iter());
138-
/// assert_eq!(it.next().get(), (&0, &1));
138+
/// assert_eq!(it.next().unwrap(), (&0, &1));
139139
/// assert!(it.next().is_none());
140140
/// ```
141141
#[inline]
@@ -151,8 +151,8 @@ pub trait Iterator<A> {
151151
/// ```rust
152152
/// let a = [1, 2];
153153
/// let mut it = a.iter().map(|&x| 2 * x);
154-
/// assert_eq!(it.next().get(), 2);
155-
/// assert_eq!(it.next().get(), 4);
154+
/// assert_eq!(it.next().unwrap(), 2);
155+
/// assert_eq!(it.next().unwrap(), 4);
156156
/// assert!(it.next().is_none());
157157
/// ```
158158
#[inline]
@@ -169,7 +169,7 @@ pub trait Iterator<A> {
169169
/// ```rust
170170
/// let a = [1, 2];
171171
/// let mut it = a.iter().filter(|&x| *x > 1);
172-
/// assert_eq!(it.next().get(), &2);
172+
/// assert_eq!(it.next().unwrap(), &2);
173173
/// assert!(it.next().is_none());
174174
/// ```
175175
#[inline]
@@ -186,7 +186,7 @@ pub trait Iterator<A> {
186186
/// ```rust
187187
/// let a = [1, 2];
188188
/// let mut it = a.iter().filter_map(|&x| if x > 1 {Some(2 * x)} else {None});
189-
/// assert_eq!(it.next().get(), 4);
189+
/// assert_eq!(it.next().unwrap(), 4);
190190
/// assert!(it.next().is_none());
191191
/// ```
192192
#[inline]
@@ -202,8 +202,8 @@ pub trait Iterator<A> {
202202
/// ```rust
203203
/// let a = [100, 200];
204204
/// let mut it = a.iter().enumerate();
205-
/// assert_eq!(it.next().get(), (0, &100));
206-
/// assert_eq!(it.next().get(), (1, &200));
205+
/// assert_eq!(it.next().unwrap(), (0, &100));
206+
/// assert_eq!(it.next().unwrap(), (1, &200));
207207
/// assert!(it.next().is_none());
208208
/// ```
209209
#[inline]
@@ -243,9 +243,9 @@ pub trait Iterator<A> {
243243
/// ```rust
244244
/// let a = [1, 2, 3, 2, 1];
245245
/// let mut it = a.iter().skip_while(|&a| *a < 3);
246-
/// assert_eq!(it.next().get(), &3);
247-
/// assert_eq!(it.next().get(), &2);
248-
/// assert_eq!(it.next().get(), &1);
246+
/// assert_eq!(it.next().unwrap(), &3);
247+
/// assert_eq!(it.next().unwrap(), &2);
248+
/// assert_eq!(it.next().unwrap(), &1);
249249
/// assert!(it.next().is_none());
250250
/// ```
251251
#[inline]
@@ -262,8 +262,8 @@ pub trait Iterator<A> {
262262
/// ```rust
263263
/// let a = [1, 2, 3, 2, 1];
264264
/// let mut it = a.iter().take_while(|&a| *a < 3);
265-
/// assert_eq!(it.next().get(), &1);
266-
/// assert_eq!(it.next().get(), &2);
265+
/// assert_eq!(it.next().unwrap(), &1);
266+
/// assert_eq!(it.next().unwrap(), &2);
267267
/// assert!(it.next().is_none());
268268
/// ```
269269
#[inline]
@@ -279,8 +279,8 @@ pub trait Iterator<A> {
279279
/// ```rust
280280
/// let a = [1, 2, 3, 4, 5];
281281
/// let mut it = a.iter().skip(3);
282-
/// assert_eq!(it.next().get(), &4);
283-
/// assert_eq!(it.next().get(), &5);
282+
/// assert_eq!(it.next().unwrap(), &4);
283+
/// assert_eq!(it.next().unwrap(), &5);
284284
/// assert!(it.next().is_none());
285285
/// ```
286286
#[inline]
@@ -296,9 +296,9 @@ pub trait Iterator<A> {
296296
/// ```rust
297297
/// let a = [1, 2, 3, 4, 5];
298298
/// let mut it = a.iter().take(3);
299-
/// assert_eq!(it.next().get(), &1);
300-
/// assert_eq!(it.next().get(), &2);
301-
/// assert_eq!(it.next().get(), &3);
299+
/// assert_eq!(it.next().unwrap(), &1);
300+
/// assert_eq!(it.next().unwrap(), &2);
301+
/// assert_eq!(it.next().unwrap(), &3);
302302
/// assert!(it.next().is_none());
303303
/// ```
304304
#[inline]
@@ -319,11 +319,11 @@ pub trait Iterator<A> {
319319
/// *fac = *fac * x;
320320
/// Some(*fac)
321321
/// });
322-
/// assert_eq!(it.next().get(), 1);
323-
/// assert_eq!(it.next().get(), 2);
324-
/// assert_eq!(it.next().get(), 6);
325-
/// assert_eq!(it.next().get(), 24);
326-
/// assert_eq!(it.next().get(), 120);
322+
/// assert_eq!(it.next().unwrap(), 1);
323+
/// assert_eq!(it.next().unwrap(), 2);
324+
/// assert_eq!(it.next().unwrap(), 6);
325+
/// assert_eq!(it.next().unwrap(), 24);
326+
/// assert_eq!(it.next().unwrap(), 120);
327327
/// assert!(it.next().is_none());
328328
/// ```
329329
#[inline]
@@ -424,16 +424,13 @@ pub trait Iterator<A> {
424424
ByRef{iter: self}
425425
}
426426

427-
/// An adaptation of an external iterator to the for-loop protocol of rust.
427+
/// Apply a function to each element, or stop iterating if the
428+
/// function returns `false`.
428429
///
429430
/// # Example
430431
///
431432
/// ```rust
432-
/// use std::iter::count;
433-
///
434-
/// for i in count(0, 10) {
435-
/// println!("{}", i);
436-
/// }
433+
/// range(0, 5).advance(|x| {print!("{} ", x); true});
437434
/// ```
438435
#[inline]
439436
fn advance(&mut self, f: &fn(A) -> bool) -> bool {
@@ -485,7 +482,7 @@ pub trait Iterator<A> {
485482
/// ```rust
486483
/// let a = [1, 2, 3, 4, 5];
487484
/// let mut it = a.iter();
488-
/// assert!(it.nth(2).get() == &3);
485+
/// assert!(it.nth(2).unwrap() == &3);
489486
/// assert!(it.nth(2) == None);
490487
/// ```
491488
#[inline]
@@ -506,7 +503,7 @@ pub trait Iterator<A> {
506503
///
507504
/// ```rust
508505
/// let a = [1, 2, 3, 4, 5];
509-
/// assert!(a.iter().last().get() == &5);
506+
/// assert!(a.iter().last().unwrap() == &5);
510507
/// ```
511508
#[inline]
512509
fn last(&mut self) -> Option<A> {
@@ -865,7 +862,7 @@ pub trait OrdIterator<A> {
865862
///
866863
/// ```rust
867864
/// let a = [1, 2, 3, 4, 5];
868-
/// assert!(a.iter().max().get() == &5);
865+
/// assert!(a.iter().max().unwrap() == &5);
869866
/// ```
870867
fn max(&mut self) -> Option<A>;
871868

@@ -875,7 +872,7 @@ pub trait OrdIterator<A> {
875872
///
876873
/// ```rust
877874
/// let a = [1, 2, 3, 4, 5];
878-
/// assert!(a.iter().min().get() == &1);
875+
/// assert!(a.iter().min().unwrap() == &1);
879876
/// ```
880877
fn min(&mut self) -> Option<A>;
881878
}

0 commit comments

Comments
 (0)