Skip to content

Commit bb12d20

Browse files
author
Ulrik Sverdrup
committed
collections: Use IterMut to indicate mutable borrow
This way we don't need PhantomData
1 parent 0a2a809 commit bb12d20

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/libcollections/vec.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -765,14 +765,16 @@ impl<T> Vec<T> {
765765
unsafe {
766766
// set self.vec length's to start, to be safe in case Drain is leaked
767767
self.set_len(start);
768-
let range_slice = slice::from_raw_parts(self.as_ptr().offset(start as isize),
769-
end - start);
768+
// Use the borrow in the IterMut to indicate borrowing behavior of the
769+
// whole Drain iterator (like &mut T).
770+
let range_slice = slice::from_raw_parts_mut(
771+
self.as_mut_ptr().offset(start as isize),
772+
end - start);
770773
Drain {
771774
tail_start: end,
772775
tail_len: len - end,
773-
iter: range_slice.iter(),
776+
iter: range_slice.iter_mut(),
774777
vec: self as *mut _,
775-
_marker: PhantomData,
776778
}
777779
}
778780
}
@@ -1832,9 +1834,8 @@ pub struct Drain<'a, T: 'a> {
18321834
/// Length of tail
18331835
tail_len: usize,
18341836
/// Current remaining range to remove
1835-
iter: slice::Iter<'a, T>,
1837+
iter: slice::IterMut<'a, T>,
18361838
vec: *mut Vec<T>,
1837-
_marker: PhantomData<&'a mut Vec<T>>,
18381839
}
18391840

18401841
unsafe impl<'a, T: Sync> Sync for Drain<'a, T> {}

0 commit comments

Comments
 (0)