Rollup merge of #89245 - DeveloperC286:iter_mut_fields_to_private, r=joshtriplett
refactor: make VecDeque's IterMut fields module-private, not just crate-private Made the fields of VecDeque's IterMut private by creating a IterMut::new(...) function to create a new instance of IterMut and migrating usage to use IterMut::new(...).
This commit is contained in:
commit
14da7fc9ae
2 changed files with 21 additions and 16 deletions
|
@ -13,10 +13,21 @@ use super::{count, wrap_index, RingSlices};
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub struct IterMut<'a, T: 'a> {
|
pub struct IterMut<'a, T: 'a> {
|
||||||
// Internal safety invariant: the entire slice is dereferencable.
|
// Internal safety invariant: the entire slice is dereferencable.
|
||||||
pub(crate) ring: *mut [T],
|
ring: *mut [T],
|
||||||
pub(crate) tail: usize,
|
tail: usize,
|
||||||
pub(crate) head: usize,
|
head: usize,
|
||||||
pub(crate) phantom: PhantomData<&'a mut [T]>,
|
phantom: PhantomData<&'a mut [T]>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, T> IterMut<'a, T> {
|
||||||
|
pub(super) unsafe fn new(
|
||||||
|
ring: *mut [T],
|
||||||
|
tail: usize,
|
||||||
|
head: usize,
|
||||||
|
phantom: PhantomData<&'a mut [T]>,
|
||||||
|
) -> Self {
|
||||||
|
IterMut { ring, tail, head, phantom }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SAFETY: we do nothing thread-local and there is no interior mutability,
|
// SAFETY: we do nothing thread-local and there is no interior mutability,
|
||||||
|
|
|
@ -1000,12 +1000,9 @@ impl<T, A: Allocator> VecDeque<T, A> {
|
||||||
pub fn iter_mut(&mut self) -> IterMut<'_, T> {
|
pub fn iter_mut(&mut self) -> IterMut<'_, T> {
|
||||||
// SAFETY: The internal `IterMut` safety invariant is established because the
|
// SAFETY: The internal `IterMut` safety invariant is established because the
|
||||||
// `ring` we create is a dereferencable slice for lifetime '_.
|
// `ring` we create is a dereferencable slice for lifetime '_.
|
||||||
IterMut {
|
let ring = ptr::slice_from_raw_parts_mut(self.ptr(), self.cap());
|
||||||
tail: self.tail,
|
|
||||||
head: self.head,
|
unsafe { IterMut::new(ring, self.tail, self.head, PhantomData) }
|
||||||
ring: ptr::slice_from_raw_parts_mut(self.ptr(), self.cap()),
|
|
||||||
phantom: PhantomData,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a pair of slices which contain, in order, the contents of the
|
/// Returns a pair of slices which contain, in order, the contents of the
|
||||||
|
@ -1192,12 +1189,9 @@ impl<T, A: Allocator> VecDeque<T, A> {
|
||||||
|
|
||||||
// SAFETY: The internal `IterMut` safety invariant is established because the
|
// SAFETY: The internal `IterMut` safety invariant is established because the
|
||||||
// `ring` we create is a dereferencable slice for lifetime '_.
|
// `ring` we create is a dereferencable slice for lifetime '_.
|
||||||
IterMut {
|
let ring = ptr::slice_from_raw_parts_mut(self.ptr(), self.cap());
|
||||||
tail,
|
|
||||||
head,
|
unsafe { IterMut::new(ring, tail, head, PhantomData) }
|
||||||
ring: ptr::slice_from_raw_parts_mut(self.ptr(), self.cap()),
|
|
||||||
phantom: PhantomData,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a draining iterator that removes the specified range in the
|
/// Creates a draining iterator that removes the specified range in the
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue