about summary refs log tree commit diff
diff options
context:
space:
mode:
authorKevin Ballard <kevin@sb.org>2014-05-03 16:11:12 -0700
committerKevin Ballard <kevin@sb.org>2014-05-08 12:06:21 -0700
commitbf1e065371f8e50f84318b45fb21a949faa9449f (patch)
tree44bc8d446e0fa05b767cb4c5245c87510a69576a
parentaa6725407ae0a2cb88458e147e76adf8bcae0961 (diff)
downloadrust-bf1e065371f8e50f84318b45fb21a949faa9449f.tar.gz
rust-bf1e065371f8e50f84318b45fb21a949faa9449f.zip
Remove FromIterator impl for ~[T]
As part of the shift from ~[T] to Vec<T>, recently ~[T] was made
non-growable. However, the FromIterator implementation for ~[T] was left
intact (albeit implemented inefficiently), which basically provided a
loophole to grow a ~[T] despite its non-growable nature. This is a
problem, both for performance reasons and because it encourages APIs to
continue returning ~[T] when they should return Vec<T>. Removing
FromIterator forces these APIs to adopt the correct type.

Furthermore, during today's weekly meeting it was decided that we should
remove all instances of ~[T] from the standard libraries in favor of
Vec<T>. Removing the FromIterator impl makes sense to do as a result.

This commit only includes the removal of the FromIterator impl. The
subsequent commits involve handling all of the breakage that results,
including changing APIs to use Vec<T> instead of ~[T]. The precise API
changes are documented in the subsequent commit messages, but each
commit is not individually marked as a breaking change.

Finally, a new trait FromVec is introduced that provides a mechanism to
convert Vec<T> back into ~[T] if truly necessary. It is a bit awkward to
use by design, and is anticipated that it will be more useful in a
post-DST world to convert to an arbitrary Foo<[T]> smart pointer.

[breaking-change]
-rw-r--r--src/libcore/should_not_exist.rs33
1 files changed, 0 insertions, 33 deletions
diff --git a/src/libcore/should_not_exist.rs b/src/libcore/should_not_exist.rs
index 50447f0c5b3..e7a1286bafc 100644
--- a/src/libcore/should_not_exist.rs
+++ b/src/libcore/should_not_exist.rs
@@ -151,39 +151,6 @@ impl<A: Clone> Clone for ~[A] {
     }
 }
 
-impl<A> FromIterator<A> for ~[A] {
-    fn from_iter<T: Iterator<A>>(mut iterator: T) -> ~[A] {
-        let (lower, _) = iterator.size_hint();
-        let cap = if lower == 0 {16} else {lower};
-        let mut cap = cap.checked_mul(&mem::size_of::<A>()).unwrap();
-        let mut len = 0;
-
-        unsafe {
-            let mut ptr = alloc(cap) as *mut Vec<A>;
-            let mut ret = cast::transmute(ptr);
-            for elt in iterator {
-                if len * mem::size_of::<A>() >= cap {
-                    cap = cap.checked_mul(&2).unwrap();
-                    let ptr2 = alloc(cap) as *mut Vec<A>;
-                    ptr::copy_nonoverlapping_memory(&mut (*ptr2).data,
-                                                    &(*ptr).data,
-                                                    len);
-                    free(ptr as *u8);
-                    cast::forget(ret);
-                    ret = cast::transmute(ptr2);
-                    ptr = ptr2;
-                }
-
-                let base = &mut (*ptr).data as *mut A;
-                intrinsics::move_val_init(&mut *base.offset(len as int), elt);
-                len += 1;
-                (*ptr).fill = len * mem::nonzero_size_of::<A>();
-            }
-            ret
-        }
-    }
-}
-
 #[cfg(not(test))]
 impl<'a,T:Clone, V: Vector<T>> Add<V, ~[T]> for &'a [T] {
     #[inline]