Skip to content

Commit c5579ca

Browse files
committed
Fallout: Port Vec to use Unique
1 parent f2529ac commit c5579ca

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

src/libcollections/vec.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ use core::default::Default;
5757
use core::fmt;
5858
use core::hash::{self, Hash};
5959
use core::iter::{repeat, FromIterator, IntoIterator};
60-
use core::marker::{self, ContravariantLifetime, InvariantType};
60+
use core::marker::PhantomData;
6161
use core::mem;
62-
use core::nonzero::NonZero;
6362
use core::num::{Int, UnsignedInt};
6463
use core::ops::{Index, IndexMut, Deref, Add};
6564
use core::ops;
6665
use core::ptr;
66+
use core::ptr::Unique;
6767
use core::raw::Slice as RawSlice;
6868
use core::slice;
6969
use core::usize;
@@ -137,10 +137,9 @@ use core::usize;
137137
#[unsafe_no_drop_flag]
138138
#[stable(feature = "rust1", since = "1.0.0")]
139139
pub struct Vec<T> {
140-
ptr: NonZero<*mut T>,
140+
ptr: Unique<T>,
141141
len: usize,
142142
cap: usize,
143-
_own: marker::PhantomData<T>,
144143
}
145144

146145
unsafe impl<T: Send> Send for Vec<T> { }
@@ -249,10 +248,9 @@ impl<T> Vec<T> {
249248
pub unsafe fn from_raw_parts(ptr: *mut T, length: usize,
250249
capacity: usize) -> Vec<T> {
251250
Vec {
252-
ptr: NonZero::new(ptr),
251+
ptr: Unique::new(ptr),
253252
len: length,
254253
cap: capacity,
255-
_own: marker::PhantomData,
256254
}
257255
}
258256

@@ -373,7 +371,7 @@ impl<T> Vec<T> {
373371
self.len * mem::size_of::<T>(),
374372
mem::min_align_of::<T>()) as *mut T;
375373
if ptr.is_null() { ::alloc::oom() }
376-
self.ptr = NonZero::new(ptr);
374+
self.ptr = Unique::new(ptr);
377375
}
378376
self.cap = self.len;
379377
}
@@ -655,7 +653,7 @@ impl<T> Vec<T> {
655653
unsafe {
656654
let ptr = alloc_or_realloc(*self.ptr, old_size, size);
657655
if ptr.is_null() { ::alloc::oom() }
658-
self.ptr = NonZero::new(ptr);
656+
self.ptr = Unique::new(ptr);
659657
}
660658
self.cap = max(self.cap, 2) * 2;
661659
}
@@ -756,7 +754,7 @@ impl<T> Vec<T> {
756754
Drain {
757755
ptr: begin,
758756
end: end,
759-
marker: ContravariantLifetime,
757+
marker: PhantomData,
760758
}
761759
}
762760
}
@@ -871,6 +869,8 @@ impl<T> Vec<T> {
871869
end_t: unsafe { start.offset(offset) },
872870
start_u: start as *mut U,
873871
end_u: start as *mut U,
872+
873+
_marker: PhantomData,
874874
};
875875
// start_t
876876
// start_u
@@ -967,8 +967,7 @@ impl<T> Vec<T> {
967967
let mut pv = PartialVecZeroSized::<T,U> {
968968
num_t: vec.len(),
969969
num_u: 0,
970-
marker_t: InvariantType,
971-
marker_u: InvariantType,
970+
marker: PhantomData,
972971
};
973972
unsafe { mem::forget(vec); }
974973

@@ -1226,7 +1225,7 @@ impl<T> Vec<T> {
12261225
unsafe {
12271226
let ptr = alloc_or_realloc(*self.ptr, self.cap * mem::size_of::<T>(), size);
12281227
if ptr.is_null() { ::alloc::oom() }
1229-
self.ptr = NonZero::new(ptr);
1228+
self.ptr = Unique::new(ptr);
12301229
}
12311230
self.cap = capacity;
12321231
}
@@ -1779,10 +1778,10 @@ impl<T> Drop for IntoIter<T> {
17791778
#[unsafe_no_drop_flag]
17801779
#[unstable(feature = "collections",
17811780
reason = "recently added as part of collections reform 2")]
1782-
pub struct Drain<'a, T> {
1781+
pub struct Drain<'a, T:'a> {
17831782
ptr: *const T,
17841783
end: *const T,
1785-
marker: ContravariantLifetime<'a>,
1784+
marker: PhantomData<&'a T>,
17861785
}
17871786

17881787
#[stable(feature = "rust1", since = "1.0.0")]
@@ -1867,9 +1866,9 @@ impl<'a, T> Drop for Drain<'a, T> {
18671866

18681867
/// Wrapper type providing a `&Vec<T>` reference via `Deref`.
18691868
#[unstable(feature = "collections")]
1870-
pub struct DerefVec<'a, T> {
1869+
pub struct DerefVec<'a, T:'a> {
18711870
x: Vec<T>,
1872-
l: ContravariantLifetime<'a>
1871+
l: PhantomData<&'a T>,
18731872
}
18741873

18751874
#[unstable(feature = "collections")]
@@ -1897,7 +1896,7 @@ pub fn as_vec<'a, T>(x: &'a [T]) -> DerefVec<'a, T> {
18971896
unsafe {
18981897
DerefVec {
18991898
x: Vec::from_raw_parts(x.as_ptr() as *mut T, x.len(), x.len()),
1900-
l: ContravariantLifetime::<'a>
1899+
l: PhantomData,
19011900
}
19021901
}
19031902
}
@@ -1921,6 +1920,8 @@ struct PartialVecNonZeroSized<T,U> {
19211920
end_u: *mut U,
19221921
start_t: *mut T,
19231922
end_t: *mut T,
1923+
1924+
_marker: PhantomData<U>,
19241925
}
19251926

19261927
/// An owned, partially type-converted vector of zero-sized elements.
@@ -1930,8 +1931,7 @@ struct PartialVecNonZeroSized<T,U> {
19301931
struct PartialVecZeroSized<T,U> {
19311932
num_t: usize,
19321933
num_u: usize,
1933-
marker_t: InvariantType<T>,
1934-
marker_u: InvariantType<U>,
1934+
marker: PhantomData<::core::cell::Cell<(T,U)>>,
19351935
}
19361936

19371937
#[unsafe_destructor]

src/libcollections/vec_map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ pub struct IntoIter<V> {
859859
}
860860

861861
#[unstable(feature = "collections")]
862-
pub struct Drain<'a, V> {
862+
pub struct Drain<'a, V:'a> {
863863
iter: FilterMap<
864864
Enumerate<vec::Drain<'a, Option<V>>>,
865865
fn((usize, Option<V>)) -> Option<(usize, V)>>

0 commit comments

Comments
 (0)