aboutsummaryrefslogtreecommitdiff
path: root/liballoc
diff options
context:
space:
mode:
Diffstat (limited to 'liballoc')
-rw-r--r--liballoc/arc.rs73
-rw-r--r--liballoc/boxed.rs17
-rw-r--r--liballoc/boxed_test.rs2
-rw-r--r--liballoc/heap.rs2
-rw-r--r--liballoc/lib.rs1
-rw-r--r--liballoc/raw_vec.rs7
-rw-r--r--liballoc/rc.rs67
7 files changed, 92 insertions, 77 deletions
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<T: ?Sized> Drop for Arc<T> {
}
}
+impl<T> Weak<T> {
+ /// Constructs a new `Weak<T>` without an accompanying instance of T.
+ ///
+ /// This allocates memory for T, but does not initialize it. Calling
+ /// Weak<T>::upgrade() on the return value always gives None.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// use std::sync::Weak;
+ ///
+ /// let empty: Weak<i64> = Weak::new();
+ /// ```
+ #[stable(feature = "downgraded_weak", since = "1.10.0")]
+ pub fn new() -> Weak<T> {
+ unsafe {
+ Weak {
+ ptr: Shared::new(Box::into_raw(box ArcInner {
+ strong: atomic::AtomicUsize::new(0),
+ weak: atomic::AtomicUsize::new(1),
+ data: uninitialized(),
+ })),
+ }
+ }
+ }
+}
+
impl<T: ?Sized> Weak<T> {
/// Upgrades a weak reference to a strong reference.
///
@@ -630,7 +657,9 @@ impl<T: ?Sized> Weak<T> {
// 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<T: ?Sized> Clone for Weak<T> {
}
}
+#[stable(feature = "downgraded_weak", since = "1.10.0")]
+impl<T> Default for Weak<T> {
+ fn default() -> Weak<T> {
+ Weak::new()
+ }
+}
+
#[stable(feature = "arc_weak", since = "1.4.0")]
impl<T: ?Sized> Drop for Weak<T> {
/// Drops the `Weak<T>`.
@@ -907,35 +943,6 @@ impl<T> From<T> for Arc<T> {
}
}
-impl<T> Weak<T> {
- /// Constructs a new `Weak<T>` without an accompanying instance of T.
- ///
- /// This allocates memory for T, but does not initialize it. Calling
- /// Weak<T>::upgrade() on the return value always gives None.
- ///
- /// # Examples
- ///
- /// ```
- /// #![feature(downgraded_weak)]
- ///
- /// use std::sync::Weak;
- ///
- /// let empty: Weak<i64> = Weak::new();
- /// ```
- #[unstable(feature = "downgraded_weak",
- reason = "recently added",
- issue = "30425")]
- pub fn new() -> Weak<T> {
- 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<I: ExactSizeIterator + ?Sized> ExactSizeIterator for Box<I> {}
/// }
/// ```
#[rustc_paren_sugar]
-#[unstable(feature = "fnbox", reason = "Newly introduced", issue = "28796")]
+#[unstable(feature = "fnbox",
+ reason = "will be deprecated if and when Box<FnOnce> becomes usable", issue = "28796")]
pub trait FnBox<A> {
type Output;
fn call_box(self: Box<Self>, args: A) -> Self::Output;
}
-#[unstable(feature = "fnbox", reason = "Newly introduced", issue = "28796")]
-impl<A, F> FnBox<A> for F where F: FnOnce<A>
+#[unstable(feature = "fnbox",
+ reason = "will be deprecated if and when Box<FnOnce> becomes usable", issue = "28796")]
+impl<A, F> FnBox<A> for F
+ where F: FnOnce<A>
{
type Output = F::Output;
@@ -542,7 +545,8 @@ impl<A, F> FnBox<A> for F where F: FnOnce<A>
}
}
-#[unstable(feature = "fnbox", reason = "Newly introduced", issue = "28796")]
+#[unstable(feature = "fnbox",
+ reason = "will be deprecated if and when Box<FnOnce> becomes usable", issue = "28796")]
impl<'a, A, R> FnOnce<A> for Box<FnBox<A, Output = R> + 'a> {
type Output = R;
@@ -551,7 +555,8 @@ impl<'a, A, R> FnOnce<A> for Box<FnBox<A, Output = R> + 'a> {
}
}
-#[unstable(feature = "fnbox", reason = "Newly introduced", issue = "28796")]
+#[unstable(feature = "fnbox",
+ reason = "will be deprecated if and when Box<FnOnce> becomes usable", issue = "28796")]
impl<'a, A, R> FnOnce<A> for Box<FnBox<A, Output = R> + 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<T> RawVec<T> {
/// 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::<T>() == 0 {
!0
@@ -577,9 +578,9 @@ impl<T> Drop for RawVec<T> {
// * 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<T: ?Sized> !marker::Sync for Weak<T> {}
#[unstable(feature = "coerce_unsized", issue = "27732")]
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Weak<U>> for Weak<T> {}
+impl<T> Weak<T> {
+ /// Constructs a new `Weak<T>` without an accompanying instance of T.
+ ///
+ /// This allocates memory for T, but does not initialize it. Calling
+ /// Weak<T>::upgrade() on the return value always gives None.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// use std::rc::Weak;
+ ///
+ /// let empty: Weak<i64> = Weak::new();
+ /// ```
+ #[stable(feature = "downgraded_weak", since = "1.10.0")]
+ pub fn new() -> Weak<T> {
+ unsafe {
+ Weak {
+ ptr: Shared::new(Box::into_raw(box RcBox {
+ strong: Cell::new(0),
+ weak: Cell::new(1),
+ value: uninitialized(),
+ })),
+ }
+ }
+ }
+}
+
impl<T: ?Sized> Weak<T> {
/// Upgrades a weak reference to a strong reference.
///
@@ -823,34 +850,10 @@ impl<T: ?Sized + fmt::Debug> fmt::Debug for Weak<T> {
}
}
-impl<T> Weak<T> {
- /// Constructs a new `Weak<T>` without an accompanying instance of T.
- ///
- /// This allocates memory for T, but does not initialize it. Calling
- /// Weak<T>::upgrade() on the return value always gives None.
- ///
- /// # Examples
- ///
- /// ```
- /// #![feature(downgraded_weak)]
- ///
- /// use std::rc::Weak;
- ///
- /// let empty: Weak<i64> = Weak::new();
- /// ```
- #[unstable(feature = "downgraded_weak",
- reason = "recently added",
- issue="30425")]
- pub fn new() -> Weak<T> {
- 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<T> Default for Weak<T> {
+ fn default() -> Weak<T> {
+ 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;