Skip to content

Commit 2ff8412

Browse files
author
blake2-ppc
committed
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.
1 parent 66fccdb commit 2ff8412

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/libstd/vec.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2106,7 +2106,8 @@ macro_rules! iterator {
21062106

21072107
#[inline]
21082108
fn size_hint(&self) -> (uint, Option<uint>) {
2109-
let exact = self.indexable();
2109+
let diff = (self.end as uint) - (self.ptr as uint);
2110+
let exact = diff / sys::nonzero_size_of::<T>();
21102111
(exact, Some(exact))
21112112
}
21122113
}
@@ -2139,8 +2140,8 @@ macro_rules! random_access_iterator {
21392140
impl<'self, T> RandomAccessIterator<$elem> for $name<'self, T> {
21402141
#[inline]
21412142
fn indexable(&self) -> uint {
2142-
let diff = (self.end as uint) - (self.ptr as uint);
2143-
diff / sys::nonzero_size_of::<T>()
2143+
let (exact, _) = self.size_hint();
2144+
exact
21442145
}
21452146

21462147
fn idx(&self, index: uint) -> Option<$elem> {
@@ -2181,7 +2182,6 @@ pub struct VecMutIterator<'self, T> {
21812182
}
21822183
iterator!{impl VecMutIterator -> &'self mut T}
21832184
double_ended_iterator!{impl VecMutIterator -> &'self mut T}
2184-
random_access_iterator!{impl VecMutIterator -> &'self mut T}
21852185
pub type MutRevIterator<'self, T> = Invert<VecMutIterator<'self, T>>;
21862186

21872187
/// An iterator that moves out of a vector.

0 commit comments

Comments
 (0)