mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-19 02:13:57 +00:00
Liballoc IntoIter limit unsafe to pointer arithmethic
This commit is contained in:
parent
2b7f87b5fa
commit
cc0d634550
@ -2697,25 +2697,21 @@ impl<T> Iterator for IntoIter<T> {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn next(&mut self) -> Option<T> {
|
fn next(&mut self) -> Option<T> {
|
||||||
unsafe {
|
if self.ptr as *const _ == self.end {
|
||||||
if self.ptr as *const _ == self.end {
|
None
|
||||||
None
|
} else if mem::size_of::<T>() == 0 {
|
||||||
} else {
|
// purposefully don't use 'ptr.offset' because for
|
||||||
if mem::size_of::<T>() == 0 {
|
// vectors with 0-size elements this would return the
|
||||||
// purposefully don't use 'ptr.offset' because for
|
// same pointer.
|
||||||
// vectors with 0-size elements this would return the
|
self.ptr = unsafe { arith_offset(self.ptr as *const T, 1) as *mut T };
|
||||||
// same pointer.
|
|
||||||
self.ptr = arith_offset(self.ptr as *const T, 1) as *mut T;
|
|
||||||
|
|
||||||
// Make up a value of this ZST.
|
// Make up a value of this ZST.
|
||||||
Some(mem::zeroed())
|
Some(unsafe { mem::zeroed() })
|
||||||
} else {
|
} else {
|
||||||
let old = self.ptr;
|
let old = self.ptr;
|
||||||
self.ptr = self.ptr.offset(1);
|
self.ptr = unsafe { self.ptr.offset(1) };
|
||||||
|
|
||||||
Some(ptr::read(old))
|
Some(unsafe { ptr::read(old) })
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user