Skip to content

Commit

Permalink
Auto merge of rust-lang#35733 - apasel422:issue-35721, r=alexcrichton
Browse files Browse the repository at this point in the history
Make `vec::IntoIter` covariant again

Closes rust-lang#35721

r? @alexcrichton
  • Loading branch information
bors authored Aug 17, 2016
2 parents 6c0d66a + 7e148cd commit 76fa587
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
15 changes: 9 additions & 6 deletions src/libcollections/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1453,10 +1453,11 @@ impl<T> IntoIterator for Vec<T> {
} else {
begin.offset(self.len() as isize) as *const T
};
let buf = ptr::read(&self.buf);
let cap = self.buf.cap();
mem::forget(self);
IntoIter {
_buf: buf,
buf: Shared::new(begin),
cap: cap,
ptr: begin,
end: end,
}
Expand Down Expand Up @@ -1708,8 +1709,9 @@ impl<'a, T> FromIterator<T> for Cow<'a, [T]> where T: Clone {
/// [`IntoIterator`]: ../../std/iter/trait.IntoIterator.html
#[stable(feature = "rust1", since = "1.0.0")]
pub struct IntoIter<T> {
_buf: RawVec<T>,
ptr: *mut T,
buf: Shared<T>,
cap: usize,
ptr: *const T,
end: *const T,
}

Expand Down Expand Up @@ -1750,7 +1752,7 @@ impl<T> IntoIter<T> {
#[unstable(feature = "vec_into_iter_as_slice", issue = "35601")]
pub fn as_mut_slice(&self) -> &mut [T] {
unsafe {
slice::from_raw_parts_mut(self.ptr, self.len())
slice::from_raw_parts_mut(self.ptr as *mut T, self.len())
}
}
}
Expand Down Expand Up @@ -1846,9 +1848,10 @@ impl<T> Drop for IntoIter<T> {
#[unsafe_destructor_blind_to_params]
fn drop(&mut self) {
// destroy the remaining elements
for _x in self {}
for _x in self.by_ref() {}

// RawVec handles deallocation
let _ = unsafe { RawVec::from_raw_parts(*self.buf, self.cap) };
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/libcollectionstest/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use std::borrow::Cow;
use std::iter::{FromIterator, repeat};
use std::mem::size_of;
use std::vec::Drain;
use std::vec::{Drain, IntoIter};

use test::Bencher;

Expand Down Expand Up @@ -537,6 +537,7 @@ fn test_cow_from() {
#[allow(dead_code)]
fn assert_covariance() {
fn drain<'new>(d: Drain<'static, &'static str>) -> Drain<'new, &'new str> { d }
fn into_iter<'new>(i: IntoIter<&'static str>) -> IntoIter<&'new str> { i }
}

#[bench]
Expand Down

0 comments on commit 76fa587

Please sign in to comment.