File tree 2 files changed +4
-15
lines changed
2 files changed +4
-15
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,6 @@ mod private_iter_index {
14
14
impl Sealed for ops:: RangeToInclusive < usize > { }
15
15
impl Sealed for ops:: RangeFrom < usize > { }
16
16
impl Sealed for ops:: RangeFull { }
17
- impl Sealed for usize { }
18
17
}
19
18
20
19
/// Used by the ``range`` function to know which iterator
53
52
type Output = Take < Skip < I > > ;
54
53
55
54
fn index ( self , iter : I ) -> Self :: Output {
55
+ debug_assert ! ( !self . is_empty( ) , "The given `RangeInclusive` is exhausted. The result of indexing with an exhausted `RangeInclusive` is unspecified." ) ;
56
56
iter. skip ( * self . start ( ) )
57
57
. take ( ( 1 + * self . end ( ) ) . saturating_sub ( * self . start ( ) ) )
58
58
}
@@ -102,17 +102,6 @@ where
102
102
}
103
103
}
104
104
105
- impl < I > IteratorIndex < I > for usize
106
- where
107
- I : Iterator ,
108
- {
109
- type Output = <Option < I :: Item > as IntoIterator >:: IntoIter ;
110
-
111
- fn index ( self , mut iter : I ) -> Self :: Output {
112
- iter. nth ( self ) . into_iter ( )
113
- }
114
- }
115
-
116
105
/// Returns an element of the iterator or an iterator
117
106
/// over a subsection of the iterator.
118
107
///
Original file line number Diff line number Diff line change @@ -513,6 +513,9 @@ pub trait Itertools: Iterator {
513
513
/// It's a generalisation of [`take`], [`skip`] and [`nth`], and uses these
514
514
/// under the hood.
515
515
///
516
+ /// # Unspecified Behavior
517
+ /// The result of indexing with an exhausted [`core::ops::RangeInclusive`] is unspecified.
518
+ ///
516
519
/// # Examples
517
520
///
518
521
/// ```
@@ -536,9 +539,6 @@ pub trait Itertools: Iterator {
536
539
///
537
540
/// range = vec.iter().get(..).copied().collect();
538
541
/// assert_eq!(range, vec);
539
- ///
540
- /// range = vec.iter().get(3).copied().collect();
541
- /// assert_eq!(&range, &[1]);
542
542
/// ```
543
543
///
544
544
/// [`take`]: https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.take
You can’t perform that action at this time.
0 commit comments