std: Remove RandomAccessIterator impl for VecMutIterator
The RandomAccessIterator implementation is not sound for the mutable vec iterator, and makes it easy to duplicate &mut element pointers.
This commit is contained in:
parent
66fccdb295
commit
2ff84124f0
1 changed files with 4 additions and 4 deletions
|
@ -2106,7 +2106,8 @@ macro_rules! iterator {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn size_hint(&self) -> (uint, Option<uint>) {
|
fn size_hint(&self) -> (uint, Option<uint>) {
|
||||||
let exact = self.indexable();
|
let diff = (self.end as uint) - (self.ptr as uint);
|
||||||
|
let exact = diff / sys::nonzero_size_of::<T>();
|
||||||
(exact, Some(exact))
|
(exact, Some(exact))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2139,8 +2140,8 @@ macro_rules! random_access_iterator {
|
||||||
impl<'self, T> RandomAccessIterator<$elem> for $name<'self, T> {
|
impl<'self, T> RandomAccessIterator<$elem> for $name<'self, T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn indexable(&self) -> uint {
|
fn indexable(&self) -> uint {
|
||||||
let diff = (self.end as uint) - (self.ptr as uint);
|
let (exact, _) = self.size_hint();
|
||||||
diff / sys::nonzero_size_of::<T>()
|
exact
|
||||||
}
|
}
|
||||||
|
|
||||||
fn idx(&self, index: uint) -> Option<$elem> {
|
fn idx(&self, index: uint) -> Option<$elem> {
|
||||||
|
@ -2181,7 +2182,6 @@ pub struct VecMutIterator<'self, T> {
|
||||||
}
|
}
|
||||||
iterator!{impl VecMutIterator -> &'self mut T}
|
iterator!{impl VecMutIterator -> &'self mut T}
|
||||||
double_ended_iterator!{impl VecMutIterator -> &'self mut T}
|
double_ended_iterator!{impl VecMutIterator -> &'self mut T}
|
||||||
random_access_iterator!{impl VecMutIterator -> &'self mut T}
|
|
||||||
pub type MutRevIterator<'self, T> = Invert<VecMutIterator<'self, T>>;
|
pub type MutRevIterator<'self, T> = Invert<VecMutIterator<'self, T>>;
|
||||||
|
|
||||||
/// An iterator that moves out of a vector.
|
/// An iterator that moves out of a vector.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue