diff --git a/library/alloc/src/vec.rs b/library/alloc/src/vec.rs index 4787c80aa494f..4cad873190f6b 100644 --- a/library/alloc/src/vec.rs +++ b/library/alloc/src/vec.rs @@ -2955,24 +2955,11 @@ impl Iterator for IntoIter { unsafe { if mem::size_of::() == 0 { mem::zeroed() } else { ptr::read(self.ptr.add(i)) } } + } + #[inline] fn last(mut self) -> Option { - unsafe { - if self.ptr as *const _ == self.end { - None - } else { - if mem::size_of::() == 0 { - // Immediately marches to end of the iterator. - self.ptr = self.end; - // Make up a value of this ZST. - Some(mem::zeroed()) - } else { - // Immediately marches to end of the iterator. - self.ptr = self.end; - Some(ptr::read(self.ptr.offset(-1))) - } - } - } + self.next_back() } }