Skip to content

Commit 91984e7

Browse files
committed
Simplify the implementation of IntoIter::last() a bit.
Suggested by @pickfire. Signed-off-by: Hanif Bin Ariffin <[email protected]>
1 parent a9919e0 commit 91984e7

File tree

1 file changed

+3
-16
lines changed

1 file changed

+3
-16
lines changed

library/alloc/src/vec.rs

+3-16
Original file line numberDiff line numberDiff line change
@@ -2955,24 +2955,11 @@ impl<T> Iterator for IntoIter<T> {
29552955
unsafe {
29562956
if mem::size_of::<T>() == 0 { mem::zeroed() } else { ptr::read(self.ptr.add(i)) }
29572957
}
2958+
}
2959+
29582960
#[inline]
29592961
fn last(mut self) -> Option<T> {
2960-
unsafe {
2961-
if self.ptr as *const _ == self.end {
2962-
None
2963-
} else {
2964-
if mem::size_of::<T>() == 0 {
2965-
// Immediately marches to end of the iterator.
2966-
self.ptr = self.end;
2967-
// Make up a value of this ZST.
2968-
Some(mem::zeroed())
2969-
} else {
2970-
// Immediately marches to end of the iterator.
2971-
self.ptr = self.end;
2972-
Some(ptr::read(self.ptr.offset(-1)))
2973-
}
2974-
}
2975-
}
2962+
self.next_back()
29762963
}
29772964
}
29782965

0 commit comments

Comments
 (0)