diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2015-02-12 10:30:39 -0500 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2015-02-18 10:25:12 -0500 |
| commit | c5579ca340b346f1b685887f7784c2e7f2090dcb (patch) | |
| tree | 75ad2381a7e6664d17c4638f346d722105c02f46 /src | |
| parent | f2529ac10d7ba68a03ce94873076afa9eb52e365 (diff) | |
| download | rust-c5579ca340b346f1b685887f7784c2e7f2090dcb.tar.gz rust-c5579ca340b346f1b685887f7784c2e7f2090dcb.zip | |
Fallout: Port Vec to use `Unique`
Diffstat (limited to 'src')
| -rw-r--r-- | src/libcollections/vec.rs | 38 | ||||
| -rw-r--r-- | src/libcollections/vec_map.rs | 2 |
2 files changed, 20 insertions, 20 deletions
diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index bde733644b5..1a03f5b31c0 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -57,13 +57,13 @@ use core::default::Default; use core::fmt; use core::hash::{self, Hash}; use core::iter::{repeat, FromIterator, IntoIterator}; -use core::marker::{self, ContravariantLifetime, InvariantType}; +use core::marker::PhantomData; use core::mem; -use core::nonzero::NonZero; use core::num::{Int, UnsignedInt}; use core::ops::{Index, IndexMut, Deref, Add}; use core::ops; use core::ptr; +use core::ptr::Unique; use core::raw::Slice as RawSlice; use core::slice; use core::usize; @@ -137,10 +137,9 @@ use core::usize; #[unsafe_no_drop_flag] #[stable(feature = "rust1", since = "1.0.0")] pub struct Vec<T> { - ptr: NonZero<*mut T>, + ptr: Unique<T>, len: usize, cap: usize, - _own: marker::PhantomData<T>, } unsafe impl<T: Send> Send for Vec<T> { } @@ -249,10 +248,9 @@ impl<T> Vec<T> { pub unsafe fn from_raw_parts(ptr: *mut T, length: usize, capacity: usize) -> Vec<T> { Vec { - ptr: NonZero::new(ptr), + ptr: Unique::new(ptr), len: length, cap: capacity, - _own: marker::PhantomData, } } @@ -373,7 +371,7 @@ impl<T> Vec<T> { self.len * mem::size_of::<T>(), mem::min_align_of::<T>()) as *mut T; if ptr.is_null() { ::alloc::oom() } - self.ptr = NonZero::new(ptr); + self.ptr = Unique::new(ptr); } self.cap = self.len; } @@ -655,7 +653,7 @@ impl<T> Vec<T> { unsafe { let ptr = alloc_or_realloc(*self.ptr, old_size, size); if ptr.is_null() { ::alloc::oom() } - self.ptr = NonZero::new(ptr); + self.ptr = Unique::new(ptr); } self.cap = max(self.cap, 2) * 2; } @@ -756,7 +754,7 @@ impl<T> Vec<T> { Drain { ptr: begin, end: end, - marker: ContravariantLifetime, + marker: PhantomData, } } } @@ -871,6 +869,8 @@ impl<T> Vec<T> { end_t: unsafe { start.offset(offset) }, start_u: start as *mut U, end_u: start as *mut U, + + _marker: PhantomData, }; // start_t // start_u @@ -967,8 +967,7 @@ impl<T> Vec<T> { let mut pv = PartialVecZeroSized::<T,U> { num_t: vec.len(), num_u: 0, - marker_t: InvariantType, - marker_u: InvariantType, + marker: PhantomData, }; unsafe { mem::forget(vec); } @@ -1226,7 +1225,7 @@ impl<T> Vec<T> { unsafe { let ptr = alloc_or_realloc(*self.ptr, self.cap * mem::size_of::<T>(), size); if ptr.is_null() { ::alloc::oom() } - self.ptr = NonZero::new(ptr); + self.ptr = Unique::new(ptr); } self.cap = capacity; } @@ -1779,10 +1778,10 @@ impl<T> Drop for IntoIter<T> { #[unsafe_no_drop_flag] #[unstable(feature = "collections", reason = "recently added as part of collections reform 2")] -pub struct Drain<'a, T> { +pub struct Drain<'a, T:'a> { ptr: *const T, end: *const T, - marker: ContravariantLifetime<'a>, + marker: PhantomData<&'a T>, } #[stable(feature = "rust1", since = "1.0.0")] @@ -1867,9 +1866,9 @@ impl<'a, T> Drop for Drain<'a, T> { /// Wrapper type providing a `&Vec<T>` reference via `Deref`. #[unstable(feature = "collections")] -pub struct DerefVec<'a, T> { +pub struct DerefVec<'a, T:'a> { x: Vec<T>, - l: ContravariantLifetime<'a> + l: PhantomData<&'a T>, } #[unstable(feature = "collections")] @@ -1897,7 +1896,7 @@ pub fn as_vec<'a, T>(x: &'a [T]) -> DerefVec<'a, T> { unsafe { DerefVec { x: Vec::from_raw_parts(x.as_ptr() as *mut T, x.len(), x.len()), - l: ContravariantLifetime::<'a> + l: PhantomData, } } } @@ -1921,6 +1920,8 @@ struct PartialVecNonZeroSized<T,U> { end_u: *mut U, start_t: *mut T, end_t: *mut T, + + _marker: PhantomData<U>, } /// An owned, partially type-converted vector of zero-sized elements. @@ -1930,8 +1931,7 @@ struct PartialVecNonZeroSized<T,U> { struct PartialVecZeroSized<T,U> { num_t: usize, num_u: usize, - marker_t: InvariantType<T>, - marker_u: InvariantType<U>, + marker: PhantomData<::core::cell::Cell<(T,U)>>, } #[unsafe_destructor] diff --git a/src/libcollections/vec_map.rs b/src/libcollections/vec_map.rs index 82ccfd0614f..cc2324c697c 100644 --- a/src/libcollections/vec_map.rs +++ b/src/libcollections/vec_map.rs @@ -859,7 +859,7 @@ pub struct IntoIter<V> { } #[unstable(feature = "collections")] -pub struct Drain<'a, V> { +pub struct Drain<'a, V:'a> { iter: FilterMap< Enumerate<vec::Drain<'a, Option<V>>>, fn((usize, Option<V>)) -> Option<(usize, V)>> |
