From ddc401e0bf4f972bc2916601797d12bb97c5f1dc Mon Sep 17 00:00:00 2001 From: pravic Date: Mon, 6 Jun 2016 23:05:39 +0300 Subject: update to 2016-06-06 --- liballoc/arc.rs | 73 +++++++++++++++++++++++++++----------------------- liballoc/boxed.rs | 17 +++++++----- liballoc/boxed_test.rs | 2 +- liballoc/heap.rs | 2 +- liballoc/lib.rs | 1 - liballoc/raw_vec.rs | 7 ++--- liballoc/rc.rs | 67 +++++++++++++++++++++++---------------------- 7 files changed, 92 insertions(+), 77 deletions(-) (limited to 'liballoc') diff --git a/liballoc/arc.rs b/liballoc/arc.rs index 4aba567..729d921 100644 --- a/liballoc/arc.rs +++ b/liballoc/arc.rs @@ -72,7 +72,7 @@ use boxed::Box; use core::sync::atomic; -use core::sync::atomic::Ordering::{Relaxed, Release, Acquire, SeqCst}; +use core::sync::atomic::Ordering::{Acquire, Relaxed, Release, SeqCst}; use core::borrow; use core::fmt; use core::cmp::Ordering; @@ -85,7 +85,7 @@ use core::ops::CoerceUnsized; use core::ptr::{self, Shared}; use core::marker::Unsize; use core::hash::{Hash, Hasher}; -use core::{usize, isize}; +use core::{isize, usize}; use core::convert::From; use heap::deallocate; @@ -592,6 +592,33 @@ impl Drop for Arc { } } +impl Weak { + /// Constructs a new `Weak` without an accompanying instance of T. + /// + /// This allocates memory for T, but does not initialize it. Calling + /// Weak::upgrade() on the return value always gives None. + /// + /// # Examples + /// + /// ``` + /// use std::sync::Weak; + /// + /// let empty: Weak = Weak::new(); + /// ``` + #[stable(feature = "downgraded_weak", since = "1.10.0")] + pub fn new() -> Weak { + unsafe { + Weak { + ptr: Shared::new(Box::into_raw(box ArcInner { + strong: atomic::AtomicUsize::new(0), + weak: atomic::AtomicUsize::new(1), + data: uninitialized(), + })), + } + } + } +} + impl Weak { /// Upgrades a weak reference to a strong reference. /// @@ -630,7 +657,9 @@ impl Weak { // See comments in `Arc::clone` for why we do this (for `mem::forget`). if n > MAX_REFCOUNT { - unsafe { abort(); } + unsafe { + abort(); + } } // Relaxed is valid for the same reason it is on Arc's Clone impl @@ -682,6 +711,13 @@ impl Clone for Weak { } } +#[stable(feature = "downgraded_weak", since = "1.10.0")] +impl Default for Weak { + fn default() -> Weak { + Weak::new() + } +} + #[stable(feature = "arc_weak", since = "1.4.0")] impl Drop for Weak { /// Drops the `Weak`. @@ -907,35 +943,6 @@ impl From for Arc { } } -impl Weak { - /// Constructs a new `Weak` without an accompanying instance of T. - /// - /// This allocates memory for T, but does not initialize it. Calling - /// Weak::upgrade() on the return value always gives None. - /// - /// # Examples - /// - /// ``` - /// #![feature(downgraded_weak)] - /// - /// use std::sync::Weak; - /// - /// let empty: Weak = Weak::new(); - /// ``` - #[unstable(feature = "downgraded_weak", - reason = "recently added", - issue = "30425")] - pub fn new() -> Weak { - unsafe { - Weak { ptr: Shared::new(Box::into_raw(box ArcInner { - strong: atomic::AtomicUsize::new(0), - weak: atomic::AtomicUsize::new(1), - data: uninitialized(), - }))} - } - } -} - #[cfg(test)] mod tests { use std::clone::Clone; @@ -943,7 +950,7 @@ mod tests { use std::mem::drop; use std::ops::Drop; use std::option::Option; - use std::option::Option::{Some, None}; + use std::option::Option::{None, Some}; use std::sync::atomic; use std::sync::atomic::Ordering::{Acquire, SeqCst}; use std::thread; diff --git a/liballoc/boxed.rs b/liballoc/boxed.rs index 7bdf9ea..51523ca 100644 --- a/liballoc/boxed.rs +++ b/liballoc/boxed.rs @@ -64,7 +64,7 @@ use core::hash::{self, Hash}; use core::marker::{self, Unsize}; use core::mem; use core::ops::{CoerceUnsized, Deref, DerefMut}; -use core::ops::{Placer, Boxed, Place, InPlace, BoxPlace}; +use core::ops::{BoxPlace, Boxed, InPlace, Place, Placer}; use core::ptr::{self, Unique}; use core::raw::TraitObject; use core::convert::From; @@ -525,15 +525,18 @@ impl ExactSizeIterator for Box {} /// } /// ``` #[rustc_paren_sugar] -#[unstable(feature = "fnbox", reason = "Newly introduced", issue = "28796")] +#[unstable(feature = "fnbox", + reason = "will be deprecated if and when Box becomes usable", issue = "28796")] pub trait FnBox { type Output; fn call_box(self: Box, args: A) -> Self::Output; } -#[unstable(feature = "fnbox", reason = "Newly introduced", issue = "28796")] -impl FnBox for F where F: FnOnce +#[unstable(feature = "fnbox", + reason = "will be deprecated if and when Box becomes usable", issue = "28796")] +impl FnBox for F + where F: FnOnce { type Output = F::Output; @@ -542,7 +545,8 @@ impl FnBox for F where F: FnOnce } } -#[unstable(feature = "fnbox", reason = "Newly introduced", issue = "28796")] +#[unstable(feature = "fnbox", + reason = "will be deprecated if and when Box becomes usable", issue = "28796")] impl<'a, A, R> FnOnce for Box + 'a> { type Output = R; @@ -551,7 +555,8 @@ impl<'a, A, R> FnOnce for Box + 'a> { } } -#[unstable(feature = "fnbox", reason = "Newly introduced", issue = "28796")] +#[unstable(feature = "fnbox", + reason = "will be deprecated if and when Box becomes usable", issue = "28796")] impl<'a, A, R> FnOnce for Box + Send + 'a> { type Output = R; diff --git a/liballoc/boxed_test.rs b/liballoc/boxed_test.rs index 120301a..8d68ce3 100644 --- a/liballoc/boxed_test.rs +++ b/liballoc/boxed_test.rs @@ -12,7 +12,7 @@ use core::any::Any; use core::ops::Deref; -use core::result::Result::{Ok, Err}; +use core::result::Result::{Err, Ok}; use core::clone::Clone; use std::boxed::Box; diff --git a/liballoc/heap.rs b/liballoc/heap.rs index 08b403a..bfed8a8 100644 --- a/liballoc/heap.rs +++ b/liballoc/heap.rs @@ -17,7 +17,7 @@ use core::{isize, usize}; #[cfg(not(test))] -use core::intrinsics::{size_of, min_align_of}; +use core::intrinsics::{min_align_of, size_of}; #[allow(improper_ctypes)] extern "C" { diff --git a/liballoc/lib.rs b/liballoc/lib.rs index c2dad9a..0293d54 100644 --- a/liballoc/lib.rs +++ b/liballoc/lib.rs @@ -90,7 +90,6 @@ #![feature(unique)] #![feature(unsafe_no_drop_flag, filling_drop)] #![feature(unsize)] -#![feature(extended_compare_and_swap)] #![cfg_attr(not(test), feature(raw, fn_traits, placement_new_protocol))] #![cfg_attr(test, feature(test, box_heap))] diff --git a/liballoc/raw_vec.rs b/liballoc/raw_vec.rs index c407cef..58c8411 100644 --- a/liballoc/raw_vec.rs +++ b/liballoc/raw_vec.rs @@ -147,6 +147,7 @@ impl RawVec { /// Gets the capacity of the allocation. /// /// This will always be `usize::MAX` if `T` is zero-sized. + #[inline(always)] pub fn cap(&self) -> usize { if mem::size_of::() == 0 { !0 @@ -577,9 +578,9 @@ impl Drop for RawVec { // * We don't overflow `usize::MAX` and actually allocate too little // // On 64-bit we just need to check for overflow since trying to allocate -// `> isize::MAX` bytes will surely fail. On 32-bit we need to add an extra -// guard for this in case we're running on a platform which can use all 4GB in -// user-space. e.g. PAE or x32 +// `> isize::MAX` bytes will surely fail. On 32-bit and 16-bit we need to add +// an extra guard for this in case we're running on a platform which can use +// all 4GB in user-space. e.g. PAE or x32 #[inline] fn alloc_guard(alloc_size: usize) { diff --git a/liballoc/rc.rs b/liballoc/rc.rs index c2f0a96..cf4fb45 100644 --- a/liballoc/rc.rs +++ b/liballoc/rc.rs @@ -159,11 +159,11 @@ use core::borrow; use core::cell::Cell; use core::cmp::Ordering; use core::fmt; -use core::hash::{Hasher, Hash}; -use core::intrinsics::{assume, abort}; +use core::hash::{Hash, Hasher}; +use core::intrinsics::{abort, assume}; use core::marker; use core::marker::Unsize; -use core::mem::{self, align_of_val, size_of_val, forget, uninitialized}; +use core::mem::{self, align_of_val, forget, size_of_val, uninitialized}; use core::ops::Deref; use core::ops::CoerceUnsized; use core::ptr::{self, Shared}; @@ -720,6 +720,33 @@ impl !marker::Sync for Weak {} #[unstable(feature = "coerce_unsized", issue = "27732")] impl, U: ?Sized> CoerceUnsized> for Weak {} +impl Weak { + /// Constructs a new `Weak` without an accompanying instance of T. + /// + /// This allocates memory for T, but does not initialize it. Calling + /// Weak::upgrade() on the return value always gives None. + /// + /// # Examples + /// + /// ``` + /// use std::rc::Weak; + /// + /// let empty: Weak = Weak::new(); + /// ``` + #[stable(feature = "downgraded_weak", since = "1.10.0")] + pub fn new() -> Weak { + unsafe { + Weak { + ptr: Shared::new(Box::into_raw(box RcBox { + strong: Cell::new(0), + weak: Cell::new(1), + value: uninitialized(), + })), + } + } + } +} + impl Weak { /// Upgrades a weak reference to a strong reference. /// @@ -823,34 +850,10 @@ impl fmt::Debug for Weak { } } -impl Weak { - /// Constructs a new `Weak` without an accompanying instance of T. - /// - /// This allocates memory for T, but does not initialize it. Calling - /// Weak::upgrade() on the return value always gives None. - /// - /// # Examples - /// - /// ``` - /// #![feature(downgraded_weak)] - /// - /// use std::rc::Weak; - /// - /// let empty: Weak = Weak::new(); - /// ``` - #[unstable(feature = "downgraded_weak", - reason = "recently added", - issue="30425")] - pub fn new() -> Weak { - unsafe { - Weak { - ptr: Shared::new(Box::into_raw(box RcBox { - strong: Cell::new(0), - weak: Cell::new(1), - value: uninitialized(), - })), - } - } +#[stable(feature = "downgraded_weak", since = "1.10.0")] +impl Default for Weak { + fn default() -> Weak { + Weak::new() } } @@ -932,7 +935,7 @@ mod tests { use std::boxed::Box; use std::cell::RefCell; use std::option::Option; - use std::option::Option::{Some, None}; + use std::option::Option::{None, Some}; use std::result::Result::{Err, Ok}; use std::mem::drop; use std::clone::Clone; -- cgit v1.2.3