diff --git a/library/core/src/slice/iter.rs b/library/core/src/slice/iter.rs index fc54ea23770..a20b7c9bef0 100644 --- a/library/core/src/slice/iter.rs +++ b/library/core/src/slice/iter.rs @@ -458,8 +458,8 @@ fn next(&mut self) -> Option<&'a [T]> { match self.v.iter().position(|x| (self.pred)(x)) { None => self.finish(), Some(idx) => { - let ret = Some(&self.v[..idx]); - self.v = &self.v[idx + 1..]; + let ret = Some(unsafe { self.v.get_unchecked(..idx) }); + self.v = unsafe { self.v.get_unchecked(idx + 1..) }; ret } } @@ -491,8 +491,8 @@ fn next_back(&mut self) -> Option<&'a [T]> { match self.v.iter().rposition(|x| (self.pred)(x)) { None => self.finish(), Some(idx) => { - let ret = Some(&self.v[idx + 1..]); - self.v = &self.v[..idx]; + let ret = Some(unsafe { self.v.get_unchecked(idx + 1..) }); + self.v = unsafe { self.v.get_unchecked(..idx) }; ret } }