summary refs log tree commit diff
diff options
context:
space:
mode:
authorAndrew Paseltiner <apaseltiner@gmail.com>2016-08-16 20:45:07 -0400
committerAlex Crichton <alex@alexcrichton.com>2016-08-22 22:41:45 -0700
commit66788cc28500b1a5e3b6a8e3901b96c3032366e2 (patch)
tree01070d1a834e305aa51209d40a70667a0ff743a2
parent4ce3c862d50d11d90cbf58e1a0444dbe72792976 (diff)
downloadrust-66788cc28500b1a5e3b6a8e3901b96c3032366e2.tar.gz
rust-66788cc28500b1a5e3b6a8e3901b96c3032366e2.zip
Make `vec::IntoIter` covariant again
Closes #35721
-rw-r--r--src/libcollections/vec.rs15
-rw-r--r--src/libcollectionstest/vec.rs3
2 files changed, 11 insertions, 7 deletions
diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs
index a6f817a8962..3aefcc7d4cf 100644
--- a/src/libcollections/vec.rs
+++ b/src/libcollections/vec.rs
@@ -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,
             }
@@ -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,
 }
 
@@ -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())
         }
     }
 }
@@ -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) };
     }
 }
 
diff --git a/src/libcollectionstest/vec.rs b/src/libcollectionstest/vec.rs
index 9556174bd22..537fabf8ab6 100644
--- a/src/libcollectionstest/vec.rs
+++ b/src/libcollectionstest/vec.rs
@@ -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;
 
@@ -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]