Skip to content

Commit 282e867

Browse files
Suggestions
Co-Authored-By: TrolledWoods <[email protected]>
1 parent 54f23e9 commit 282e867

File tree

2 files changed

+4
-15
lines changed

2 files changed

+4
-15
lines changed

src/iter_index.rs

+1-12
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ mod private_iter_index {
1414
impl Sealed for ops::RangeToInclusive<usize> {}
1515
impl Sealed for ops::RangeFrom<usize> {}
1616
impl Sealed for ops::RangeFull {}
17-
impl Sealed for usize {}
1817
}
1918

2019
/// Used by the ``range`` function to know which iterator
@@ -53,6 +52,7 @@ where
5352
type Output = Take<Skip<I>>;
5453

5554
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.");
5656
iter.skip(*self.start())
5757
.take((1 + *self.end()).saturating_sub(*self.start()))
5858
}
@@ -102,17 +102,6 @@ where
102102
}
103103
}
104104

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-
116105
/// Returns an element of the iterator or an iterator
117106
/// over a subsection of the iterator.
118107
///

src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,9 @@ pub trait Itertools: Iterator {
513513
/// It's a generalisation of [`take`], [`skip`] and [`nth`], and uses these
514514
/// under the hood.
515515
///
516+
/// # Unspecified Behavior
517+
/// The result of indexing with an exhausted [`core::ops::RangeInclusive`] is unspecified.
518+
///
516519
/// # Examples
517520
///
518521
/// ```
@@ -536,9 +539,6 @@ pub trait Itertools: Iterator {
536539
///
537540
/// range = vec.iter().get(..).copied().collect();
538541
/// assert_eq!(range, vec);
539-
///
540-
/// range = vec.iter().get(3).copied().collect();
541-
/// assert_eq!(&range, &[1]);
542542
/// ```
543543
///
544544
/// [`take`]: https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.take

0 commit comments

Comments
 (0)