From e1e34e9275918679336210874f8dd770323daa81 Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Mon, 11 May 2015 09:34:59 -0700 Subject: [PATCH] Reintroduce non-null assumptions in core::slice iterators The previous assumptions were not valid for slices of zero-sized elements. --- src/libcore/slice.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index f9aa83d241a..3abba314558 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -665,10 +665,14 @@ impl<'a, T> Iterator for $name<'a, T> { #[inline] fn next(&mut self) -> Option<$elem> { // could be implemented with slices, but this avoids bounds checks - unsafe { - if self.ptr == self.end { - None - } else { + if self.ptr == self.end { + None + } else { + unsafe { + if mem::size_of::() != 0 { + ::intrinsics::assume(!self.ptr.is_null()); + ::intrinsics::assume(!self.end.is_null()); + } let old = self.ptr; self.ptr = slice_offset!(self.ptr, 1); Some(slice_ref!(old)) @@ -706,11 +710,15 @@ impl<'a, T> DoubleEndedIterator for $name<'a, T> { #[inline] fn next_back(&mut self) -> Option<$elem> { // could be implemented with slices, but this avoids bounds checks - unsafe { - if self.end == self.ptr { - None - } else { + if self.end == self.ptr { + None + } else { + unsafe { self.end = slice_offset!(self.end, -1); + if mem::size_of::() != 0 { + ::intrinsics::assume(!self.ptr.is_null()); + ::intrinsics::assume(!self.end.is_null()); + } Some(slice_ref!(self.end)) } } -- GitLab