diff options
| author | Brad Gibson <b2b@humanenginuity.com> | 2018-05-06 07:56:53 -0700 |
|---|---|---|
| committer | Brad Gibson <b2b@humanenginuity.com> | 2018-05-06 07:56:53 -0700 |
| commit | 6a78c0a10f2e719117fe4bb929bfb38549acfeec (patch) | |
| tree | 0089dcdd34bfa5ba430ed33163264b147677be59 /src/liballoc | |
| parent | e1d5509bf381d978a1894b6ba869c3b56dd3eeca (diff) | |
| parent | 6f721f54c6fb1de9cf00eb9d2d050f818c882871 (diff) | |
| download | rust-6a78c0a10f2e719117fe4bb929bfb38549acfeec.tar.gz rust-6a78c0a10f2e719117fe4bb929bfb38549acfeec.zip | |
resolved conflict with upstream commit
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/alloc.rs | 14 | ||||
| -rw-r--r-- | src/liballoc/arc.rs | 5 | ||||
| -rw-r--r-- | src/liballoc/boxed.rs | 1 | ||||
| -rw-r--r-- | src/liballoc/lib.rs | 5 | ||||
| -rw-r--r-- | src/liballoc/raw_vec.rs | 10 | ||||
| -rw-r--r-- | src/liballoc/rc.rs | 5 | ||||
| -rw-r--r-- | src/liballoc/tests/lib.rs | 2 | ||||
| -rw-r--r-- | src/liballoc/tests/slice.rs | 1 | ||||
| -rw-r--r-- | src/liballoc/vec.rs | 3 |
9 files changed, 31 insertions, 15 deletions
diff --git a/src/liballoc/alloc.rs b/src/liballoc/alloc.rs index c0372d24ed5..f59c9f7fd61 100644 --- a/src/liballoc/alloc.rs +++ b/src/liballoc/alloc.rs @@ -16,7 +16,7 @@ issue = "32838")] use core::intrinsics::{min_align_of_val, size_of_val}; -use core::ptr::NonNull; +use core::ptr::{NonNull, Unique}; use core::usize; #[doc(inline)] @@ -152,9 +152,17 @@ unsafe fn exchange_malloc(size: usize, align: usize) -> *mut u8 { } } -#[cfg_attr(not(test), lang = "box_free")] +#[cfg(stage0)] +#[lang = "box_free"] +#[inline] +unsafe fn old_box_free<T: ?Sized>(ptr: *mut T) { + box_free(Unique::new_unchecked(ptr)) +} + +#[cfg_attr(not(any(test, stage0)), lang = "box_free")] #[inline] -pub(crate) unsafe fn box_free<T: ?Sized>(ptr: *mut T) { +pub(crate) unsafe fn box_free<T: ?Sized>(ptr: Unique<T>) { + let ptr = ptr.as_ptr(); let size = size_of_val(&*ptr); let align = min_align_of_val(&*ptr); // We do not allocate for Box<T> when T is ZST, so deallocation is also not necessary. diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs index e52a0216dd3..d0950bff9ce 100644 --- a/src/liballoc/arc.rs +++ b/src/liballoc/arc.rs @@ -566,7 +566,8 @@ impl<T: ?Sized> Arc<T> { fn from_box(v: Box<T>) -> Arc<T> { unsafe { - let bptr = Box::into_raw(v); + let box_unique = Box::into_unique(v); + let bptr = box_unique.as_ptr(); let value_size = size_of_val(&*bptr); let ptr = Self::allocate_for_ptr(bptr); @@ -578,7 +579,7 @@ impl<T: ?Sized> Arc<T> { value_size); // Free the allocation without dropping its contents - box_free(bptr); + box_free(box_unique); Arc { ptr: NonNull::new_unchecked(ptr), phantom: PhantomData } } diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 5ebd2cc6146..1b4f86dcfac 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -184,6 +184,7 @@ impl<T: ?Sized> Box<T> { #[unstable(feature = "ptr_internals", issue = "0", reason = "use into_raw_non_null instead")] #[inline] + #[doc(hidden)] pub fn into_unique(b: Box<T>) -> Unique<T> { let unique = b.0; mem::forget(b); diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index 021395d0c82..da4b76a4d52 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -96,7 +96,7 @@ #![feature(dropck_eyepatch)] #![feature(exact_size_is_empty)] #![feature(fmt_internals)] -#![feature(fn_must_use)] +#![cfg_attr(stage0, feature(fn_must_use))] #![feature(from_ref)] #![feature(fundamental)] #![feature(lang_items)] @@ -122,8 +122,9 @@ #![feature(on_unimplemented)] #![feature(exact_chunks)] #![feature(pointer_methods)] -#![feature(inclusive_range_fields)] +#![feature(inclusive_range_methods)] #![cfg_attr(stage0, feature(generic_param_attrs))] +#![feature(rustc_const_unstable)] #![cfg_attr(not(test), feature(fn_traits, i128))] #![cfg_attr(test, feature(test))] diff --git a/src/liballoc/raw_vec.rs b/src/liballoc/raw_vec.rs index 7ef0a27fc72..eb25ae17511 100644 --- a/src/liballoc/raw_vec.rs +++ b/src/liballoc/raw_vec.rs @@ -56,14 +56,16 @@ pub struct RawVec<T, A: Alloc = Global> { impl<T, A: Alloc> RawVec<T, A> { /// Like `new` but parameterized over the choice of allocator for /// the returned RawVec. - pub fn new_in(a: A) -> Self { + pub const fn new_in(a: A) -> Self { // !0 is usize::MAX. This branch should be stripped at compile time. - let cap = if mem::size_of::<T>() == 0 { !0 } else { 0 }; + // FIXME(mark-i-m): use this line when `if`s are allowed in `const` + //let cap = if mem::size_of::<T>() == 0 { !0 } else { 0 }; // Unique::empty() doubles as "unallocated" and "zero-sized allocation" RawVec { ptr: Unique::empty(), - cap, + // FIXME(mark-i-m): use `cap` when ifs are allowed in const + cap: [0, !0][(mem::size_of::<T>() == 0) as usize], a, } } @@ -120,7 +122,7 @@ impl<T> RawVec<T, Global> { /// RawVec with capacity 0. If T has 0 size, then it makes a /// RawVec with capacity `usize::MAX`. Useful for implementing /// delayed allocation. - pub fn new() -> Self { + pub const fn new() -> Self { Self::new_in(Global) } diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 8fb8e111754..d0188c6e828 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -681,7 +681,8 @@ impl<T: ?Sized> Rc<T> { fn from_box(v: Box<T>) -> Rc<T> { unsafe { - let bptr = Box::into_raw(v); + let box_unique = Box::into_unique(v); + let bptr = box_unique.as_ptr(); let value_size = size_of_val(&*bptr); let ptr = Self::allocate_for_ptr(bptr); @@ -693,7 +694,7 @@ impl<T: ?Sized> Rc<T> { value_size); // Free the allocation without dropping its contents - box_free(bptr); + box_free(box_unique); Rc { ptr: NonNull::new_unchecked(ptr), phantom: PhantomData } } diff --git a/src/liballoc/tests/lib.rs b/src/liballoc/tests/lib.rs index 32272169307..1c8ff316e55 100644 --- a/src/liballoc/tests/lib.rs +++ b/src/liballoc/tests/lib.rs @@ -25,7 +25,7 @@ #![feature(try_reserve)] #![feature(unboxed_closures)] #![feature(exact_chunks)] -#![feature(inclusive_range_fields)] +#![feature(inclusive_range_methods)] extern crate alloc_system; extern crate core; diff --git a/src/liballoc/tests/slice.rs b/src/liballoc/tests/slice.rs index 99d9c51efc7..6fd0b33f02a 100644 --- a/src/liballoc/tests/slice.rs +++ b/src/liballoc/tests/slice.rs @@ -1282,6 +1282,7 @@ fn test_box_slice_clone() { } #[test] +#[allow(unused_must_use)] // here, we care about the side effects of `.clone()` #[cfg_attr(target_os = "emscripten", ignore)] fn test_box_slice_clone_panics() { use std::sync::Arc; diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index b184404c15b..35d0a69a05a 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -322,7 +322,8 @@ impl<T> Vec<T> { /// ``` #[inline] #[stable(feature = "rust1", since = "1.0.0")] - pub fn new() -> Vec<T> { + #[rustc_const_unstable(feature = "const_vec_new")] + pub const fn new() -> Vec<T> { Vec { buf: RawVec::new(), len: 0, |
