diff options
| author | The8472 <git@infinite-source.de> | 2021-07-13 23:13:27 +0200 |
|---|---|---|
| committer | The8472 <git@infinite-source.de> | 2021-09-30 21:23:30 +0200 |
| commit | ffd7ade2035eb92c77421ca7dcde4cf40c863c7b (patch) | |
| tree | 7eacfde60eb20827dfe052086932a7797eecd42d /library/alloc | |
| parent | 6654a0bbdc5040a35e2e02e7a4a49726727ff221 (diff) | |
| download | rust-ffd7ade2035eb92c77421ca7dcde4cf40c863c7b.tar.gz rust-ffd7ade2035eb92c77421ca7dcde4cf40c863c7b.zip | |
fix issues pointed out in review
Diffstat (limited to 'library/alloc')
| -rw-r--r-- | library/alloc/src/vec/into_iter.rs | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/library/alloc/src/vec/into_iter.rs b/library/alloc/src/vec/into_iter.rs index eae9ad076dc..8a2d254a834 100644 --- a/library/alloc/src/vec/into_iter.rs +++ b/library/alloc/src/vec/into_iter.rs @@ -164,18 +164,19 @@ impl<T, A: Allocator> Iterator for IntoIter<T, A> { #[inline] fn advance_by(&mut self, n: usize) -> Result<(), usize> { let step_size = self.len().min(n); + let to_drop = ptr::slice_from_raw_parts_mut(self.ptr as *mut T, step_size); if mem::size_of::<T>() == 0 { // SAFETY: due to unchecked casts of unsigned amounts to signed offsets the wraparound // effectively results in unsigned pointers representing positions 0..usize::MAX, // which is valid for ZSTs. self.ptr = unsafe { arith_offset(self.ptr as *const i8, step_size as isize) as *mut T } } else { - let to_drop = ptr::slice_from_raw_parts_mut(self.ptr as *mut T, step_size); // SAFETY: the min() above ensures that step_size is in bounds - unsafe { - self.ptr = self.ptr.add(step_size); - ptr::drop_in_place(to_drop); - } + self.ptr = unsafe { self.ptr.add(step_size) }; + } + // SAFETY: the min() above ensures that step_size is in bounds + unsafe { + ptr::drop_in_place(to_drop); } if step_size < n { return Err(step_size); @@ -237,11 +238,11 @@ impl<T, A: Allocator> DoubleEndedIterator for IntoIter<T, A> { } else { // SAFETY: same as for advance_by() self.end = unsafe { self.end.offset(step_size.wrapping_neg() as isize) }; - let to_drop = ptr::slice_from_raw_parts_mut(self.end as *mut T, step_size); - // SAFETY: same as for advance_by() - unsafe { - ptr::drop_in_place(to_drop); - } + } + let to_drop = ptr::slice_from_raw_parts_mut(self.end as *mut T, step_size); + // SAFETY: same as for advance_by() + unsafe { + ptr::drop_in_place(to_drop); } if step_size < n { return Err(step_size); |
