diff options
| author | Nick Cameron <ncameron@mozilla.com> | 2014-08-04 14:20:11 +0200 |
|---|---|---|
| committer | Nick Cameron <ncameron@mozilla.com> | 2014-08-26 12:38:51 +1200 |
| commit | 3e626375d8d2226a203bf6ea6e98dab14774c59f (patch) | |
| tree | 9be8320420b1c904670b7e12ccff8bc3080b2eec /src/libcollections | |
| parent | 37a94b80f207e86017e54056ced2dc9674907ae3 (diff) | |
| download | rust-3e626375d8d2226a203bf6ea6e98dab14774c59f.tar.gz rust-3e626375d8d2226a203bf6ea6e98dab14774c59f.zip | |
DST coercions and DST structs
[breaking-change]
1. The internal layout for traits has changed from (vtable, data) to (data, vtable). If you were relying on this in unsafe transmutes, you might get some very weird and apparently unrelated errors. You should not be doing this! Prefer not to do this at all, but if you must, you should use raw::TraitObject rather than hardcoding rustc's internal representation into your code.
2. The minimal type of reference-to-vec-literals (e.g., `&[1, 2, 3]`) is now a fixed size vec (e.g., `&[int, ..3]`) where it used to be an unsized vec (e.g., `&[int]`). If you want the unszied type, you must explicitly give the type (e.g., `let x: &[_] = &[1, 2, 3]`). Note in particular where multiple blocks must have the same type (e.g., if and else clauses, vec elements), the compiler will not coerce to the unsized type without a hint. E.g., `[&[1], &[1, 2]]` used to be a valid expression of type '[&[int]]'. It no longer type checks since the first element now has type `&[int, ..1]` and the second has type &[int, ..2]` which are incompatible.
3. The type of blocks (including functions) must be coercible to the expected type (used to be a subtype). Mostly this makes things more flexible and not less (in particular, in the case of coercing function bodies to the return type). However, in some rare cases, this is less flexible. TBH, I'm not exactly sure of the exact effects. I think the change causes us to resolve inferred type variables slightly earlier which might make us slightly more restrictive. Possibly it only affects blocks with unreachable code. E.g., `if ... { fail!(); "Hello" }` used to type check, it no longer does. The fix is to add a semicolon after the string.
Diffstat (limited to 'src/libcollections')
| -rw-r--r-- | src/libcollections/slice.rs | 60 |
1 files changed, 0 insertions, 60 deletions
diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 55723ec10a0..71b9673d279 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -92,8 +92,6 @@ use core::iter::{range_step, MultiplicativeIterator}; use MutableSeq; use vec::Vec; -#[cfg(not(stage0))] -use raw::Slice; pub use core::slice::{Chunks, Slice, ImmutableSlice, ImmutablePartialEqSlice}; pub use core::slice::{ImmutableOrdSlice, MutableSlice, Items, MutItems}; @@ -284,64 +282,6 @@ pub trait CloneableVector<T> { impl<'a, T: Clone> CloneableVector<T> for &'a [T] { /// Returns a copy of `v`. - #[cfg(not(stage0))] - fn to_owned(&self) -> ~[T] { - use num::CheckedMul; - use option::Expect; - - let len = self.len(); - - if len == 0 { - unsafe { - let slice: Slice<T> = Slice{data: 0 as *T, len: 0}; - mem::transmute(slice) - } - } else { - let unit_size = mem::size_of::<T>(); - let data_size = if unit_size == 0 { - len - } else { - let data_size = len.checked_mul(&unit_size); - data_size.expect("overflow in from_iter()") - }; - - unsafe { - // this should pass the real required alignment - let ret = allocate(data_size, 8) as *mut T; - - if unit_size > 0 { - // Be careful with the following loop. We want it to be optimized - // to a memcpy (or something similarly fast) when T is Copy. LLVM - // is easily confused, so any extra operations during the loop can - // prevent this optimization. - let mut i = 0; - let p = &mut (*ret) as *mut _ as *mut T; - try_finally( - &mut i, (), - |i, ()| while *i < len { - mem::move_val_init( - &mut(*p.offset(*i as int)), - self.unsafe_ref(*i).clone()); - *i += 1; - }, - |i| if *i < len { - // we must be failing, clean up after ourselves - for j in range(0, *i as int) { - ptr::read(&*p.offset(j)); - } - // FIXME: #13994 (should pass align and size here) - deallocate(ret as *mut u8, 0, 8); - }); - } - let slice: Slice<T> = Slice{data: ret as *T, len: len}; - mem::transmute(slice) - } - } - } - - /// Returns a copy of `v`. - // NOTE: remove after snapshot - #[cfg(stage0)] #[inline] fn to_vec(&self) -> Vec<T> { Vec::from_slice(*self) } |
