diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index e4d2ab198630a..838480c88895c 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -137,7 +137,7 @@ pub trait Iterator { /// /// ``` /// let a = [1, 2, 3, 4, 5]; - /// assert_eq!(a.iter().last().unwrap(), &5); + /// assert_eq!(a.iter().last(), Some(&5)); /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] @@ -155,7 +155,7 @@ pub trait Iterator { /// ``` /// let a = [1, 2, 3, 4, 5]; /// let mut it = a.iter(); - /// assert_eq!(it.nth(2).unwrap(), &3); + /// assert_eq!(it.nth(2), Some(&3)); /// assert_eq!(it.nth(2), None); /// ``` #[inline] @@ -178,8 +178,8 @@ pub trait Iterator { /// let a = [0]; /// let b = [1]; /// let mut it = a.iter().chain(b.iter()); - /// assert_eq!(it.next().unwrap(), &0); - /// assert_eq!(it.next().unwrap(), &1); + /// assert_eq!(it.next(), Some(&0)); + /// assert_eq!(it.next(), Some(&1)); /// assert!(it.next().is_none()); /// ``` #[inline] @@ -201,7 +201,7 @@ pub trait Iterator { /// let a = [0]; /// let b = [1]; /// let mut it = a.iter().zip(b.iter()); - /// assert_eq!(it.next().unwrap(), (&0, &1)); + /// assert_eq!(it.next(), Some((&0, &1))); /// assert!(it.next().is_none()); /// ``` /// @@ -234,8 +234,8 @@ pub trait Iterator { /// ``` /// let a = [1, 2]; /// let mut it = a.iter().map(|&x| 2 * x); - /// assert_eq!(it.next().unwrap(), 2); - /// assert_eq!(it.next().unwrap(), 4); + /// assert_eq!(it.next(), Some(2)); + /// assert_eq!(it.next(), Some(4)); /// assert!(it.next().is_none()); /// ``` #[inline] @@ -255,7 +255,7 @@ pub trait Iterator { /// ``` /// let a = [1, 2]; /// let mut it = a.iter().filter(|&x| *x > 1); - /// assert_eq!(it.next().unwrap(), &2); + /// assert_eq!(it.next(), Some(&2)); /// assert!(it.next().is_none()); /// ``` #[inline] @@ -275,7 +275,7 @@ pub trait Iterator { /// ``` /// let a = [1, 2]; /// let mut it = a.iter().filter_map(|&x| if x > 1 {Some(2 * x)} else {None}); - /// assert_eq!(it.next().unwrap(), 4); + /// assert_eq!(it.next(), Some(4)); /// assert!(it.next().is_none()); /// ``` #[inline] @@ -310,8 +310,8 @@ pub trait Iterator { /// ``` /// let a = [100, 200]; /// let mut it = a.iter().enumerate(); - /// assert_eq!(it.next().unwrap(), (0, &100)); - /// assert_eq!(it.next().unwrap(), (1, &200)); + /// assert_eq!(it.next(), Some((0, &100))); + /// assert_eq!(it.next(), Some((1, &200))); /// assert!(it.next().is_none()); /// ``` #[inline] @@ -329,12 +329,12 @@ pub trait Iterator { /// # #![feature(core)] /// let xs = [100, 200, 300]; /// let mut it = xs.iter().cloned().peekable(); - /// assert_eq!(*it.peek().unwrap(), 100); - /// assert_eq!(it.next().unwrap(), 100); - /// assert_eq!(it.next().unwrap(), 200); - /// assert_eq!(*it.peek().unwrap(), 300); - /// assert_eq!(*it.peek().unwrap(), 300); - /// assert_eq!(it.next().unwrap(), 300); + /// assert_eq!(*it.peek(), Some(100)); + /// assert_eq!(it.next(), Some(100)); + /// assert_eq!(it.next(), Some(200)); + /// assert_eq!(*it.peek(), Some(300)); + /// assert_eq!(*it.peek(), Some(300)); + /// assert_eq!(it.next(), Some(300)); /// assert!(it.peek().is_none()); /// assert!(it.next().is_none()); /// ``` @@ -353,9 +353,9 @@ pub trait Iterator { /// ``` /// let a = [1, 2, 3, 4, 5]; /// let mut it = a.iter().skip_while(|&a| *a < 3); - /// assert_eq!(it.next().unwrap(), &3); - /// assert_eq!(it.next().unwrap(), &4); - /// assert_eq!(it.next().unwrap(), &5); + /// assert_eq!(it.next(), Some(&3)); + /// assert_eq!(it.next(), Some(&4)); + /// assert_eq!(it.next(), Some(&5)); /// assert!(it.next().is_none()); /// ``` #[inline] @@ -375,8 +375,8 @@ pub trait Iterator { /// ``` /// let a = [1, 2, 3, 4, 5]; /// let mut it = a.iter().take_while(|&a| *a < 3); - /// assert_eq!(it.next().unwrap(), &1); - /// assert_eq!(it.next().unwrap(), &2); + /// assert_eq!(it.next(), Some(&1)); + /// assert_eq!(it.next(), Some(&2)); /// assert!(it.next().is_none()); /// ``` #[inline] @@ -395,8 +395,8 @@ pub trait Iterator { /// ``` /// let a = [1, 2, 3, 4, 5]; /// let mut it = a.iter().skip(3); - /// assert_eq!(it.next().unwrap(), &4); - /// assert_eq!(it.next().unwrap(), &5); + /// assert_eq!(it.next(), Some(&4)); + /// assert_eq!(it.next(), Some(&5)); /// assert!(it.next().is_none()); /// ``` #[inline] @@ -413,9 +413,9 @@ pub trait Iterator { /// ``` /// let a = [1, 2, 3, 4, 5]; /// let mut it = a.iter().take(3); - /// assert_eq!(it.next().unwrap(), &1); - /// assert_eq!(it.next().unwrap(), &2); - /// assert_eq!(it.next().unwrap(), &3); + /// assert_eq!(it.next(), Some(&1)); + /// assert_eq!(it.next(), Some(&2)); + /// assert_eq!(it.next(), Some(&3)); /// assert!(it.next().is_none()); /// ``` #[inline] @@ -437,11 +437,11 @@ pub trait Iterator { /// *fac = *fac * x; /// Some(*fac) /// }); - /// assert_eq!(it.next().unwrap(), 1); - /// assert_eq!(it.next().unwrap(), 2); - /// assert_eq!(it.next().unwrap(), 6); - /// assert_eq!(it.next().unwrap(), 24); - /// assert_eq!(it.next().unwrap(), 120); + /// assert_eq!(it.next(), Some(1)); + /// assert_eq!(it.next(), Some(2)); + /// assert_eq!(it.next(), Some(6)); + /// assert_eq!(it.next(), Some(24)); + /// assert_eq!(it.next(), Some(120)); /// assert!(it.next().is_none()); /// ``` #[inline] @@ -680,7 +680,7 @@ pub trait Iterator { /// ``` /// let a = [1, 2, 3, 4, 5]; /// let mut it = a.iter(); - /// assert_eq!(it.find(|&x| *x == 3).unwrap(), &3); + /// assert_eq!(it.find(|&x| *x == 3), Some(&3)); /// assert_eq!(it.collect::>(), [&4, &5]); #[inline] #[stable(feature = "rust1", since = "1.0.0")] @@ -715,7 +715,7 @@ pub trait Iterator { /// ``` /// let a = [1, 2, 3, 4, 5]; /// let mut it = a.iter(); - /// assert_eq!(it.position(|x| *x == 3).unwrap(), 2); + /// assert_eq!(it.position(|x| *x == 3), Some(2)); /// assert_eq!(it.collect::>(), [&4, &5]); #[inline] #[stable(feature = "rust1", since = "1.0.0")] @@ -743,7 +743,7 @@ pub trait Iterator { /// ``` /// let a = [1, 2, 2, 4, 5]; /// let mut it = a.iter(); - /// assert_eq!(it.rposition(|x| *x == 2).unwrap(), 2); + /// assert_eq!(it.rposition(|x| *x == 2), Some(2)); /// assert_eq!(it.collect::>(), [&1, &2]); #[inline] #[stable(feature = "rust1", since = "1.0.0")] @@ -773,7 +773,7 @@ pub trait Iterator { /// /// ``` /// let a = [1, 2, 3, 4, 5]; - /// assert_eq!(a.iter().max().unwrap(), &5); + /// assert_eq!(a.iter().max(), Some(&5)); /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] @@ -796,7 +796,7 @@ pub trait Iterator { /// /// ``` /// let a = [1, 2, 3, 4, 5]; - /// assert_eq!(a.iter().min().unwrap(), &1); + /// assert_eq!(a.iter().min(), Some(&1)); /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] @@ -900,7 +900,7 @@ pub trait Iterator { /// # #![feature(core)] /// /// let a = [-3_i32, 0, 1, 5, -10]; - /// assert_eq!(*a.iter().max_by(|x| x.abs()).unwrap(), -10); + /// assert_eq!(*a.iter().max_by(|x| x.abs()), Some(-10)); /// ``` #[inline] #[unstable(feature = "core", @@ -929,7 +929,7 @@ pub trait Iterator { /// # #![feature(core)] /// /// let a = [-3_i32, 0, 1, 5, -10]; - /// assert_eq!(*a.iter().min_by(|x| x.abs()).unwrap(), 0); + /// assert_eq!(*a.iter().min_by(|x| x.abs()), Some(0)); /// ``` #[inline] #[unstable(feature = "core", @@ -1025,9 +1025,9 @@ pub trait Iterator { /// ``` /// let a = [1, 2]; /// let mut it = a.iter().cycle(); - /// assert_eq!(it.next().unwrap(), &1); - /// assert_eq!(it.next().unwrap(), &2); - /// assert_eq!(it.next().unwrap(), &1); + /// assert_eq!(it.next(), Some(&1)); + /// assert_eq!(it.next(), Some(&2)); + /// assert_eq!(it.next(), Some(&1)); /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline]