]> git.proxmox.com Git - rustc.git/blobdiff - src/liballoc/boxed.rs
Imported Upstream version 1.6.0+dfsg1
[rustc.git] / src / liballoc / boxed.rs
index 4783b4339dac3af888633b490e6c2cea36b88e2c..1afb49d9184b5001567325f9b30525a1eac646a6 100644 (file)
@@ -67,6 +67,7 @@ use core::ops::{CoerceUnsized, Deref, DerefMut};
 use core::ops::{Placer, Boxed, Place, InPlace, BoxPlace};
 use core::ptr::{self, Unique};
 use core::raw::TraitObject;
+use core::convert::From;
 
 /// A value that represents the heap. This is the default place that the `box`
 /// keyword allocates into when no place is supplied.
@@ -87,8 +88,7 @@ use core::raw::TraitObject;
 #[unstable(feature = "box_heap",
            reason = "may be renamed; uncertain about custom allocator design",
            issue = "27779")]
-pub const HEAP: ExchangeHeapSingleton =
-    ExchangeHeapSingleton { _force_singleton: () };
+pub const HEAP: ExchangeHeapSingleton = ExchangeHeapSingleton { _force_singleton: () };
 
 /// This the singleton type used solely for `boxed::HEAP`.
 #[unstable(feature = "box_heap",
@@ -104,7 +104,6 @@ pub struct ExchangeHeapSingleton {
 /// See the [module-level documentation](../../std/boxed/index.html) for more.
 #[lang = "owned_box"]
 #[stable(feature = "rust1", since = "1.0.0")]
-#[fundamental]
 pub struct Box<T: ?Sized>(Unique<T>);
 
 /// `IntermediateBox` represents uninitialized backing storage for `Box`.
@@ -135,6 +134,9 @@ pub struct IntermediateBox<T: ?Sized> {
     marker: marker::PhantomData<*mut T>,
 }
 
+#[unstable(feature = "placement_in",
+           reason = "placement box design is still being worked out.",
+           issue = "27779")]
 impl<T> Place<T> for IntermediateBox<T> {
     fn pointer(&mut self) -> *mut T {
         self.ptr as *mut T
@@ -169,12 +171,18 @@ fn make_place<T>() -> IntermediateBox<T> {
     }
 }
 
+#[unstable(feature = "placement_in",
+           reason = "placement box design is still being worked out.",
+           issue = "27779")]
 impl<T> BoxPlace<T> for IntermediateBox<T> {
     fn make_place() -> IntermediateBox<T> {
         make_place()
     }
 }
 
+#[unstable(feature = "placement_in",
+           reason = "placement box design is still being worked out.",
+           issue = "27779")]
 impl<T> InPlace<T> for IntermediateBox<T> {
     type Owner = Box<T>;
     unsafe fn finalize(self) -> Box<T> {
@@ -182,6 +190,7 @@ impl<T> InPlace<T> for IntermediateBox<T> {
     }
 }
 
+#[unstable(feature = "placement_new_protocol", issue = "27779")]
 impl<T> Boxed for Box<T> {
     type Data = T;
     type Place = IntermediateBox<T>;
@@ -190,6 +199,9 @@ impl<T> Boxed for Box<T> {
     }
 }
 
+#[unstable(feature = "placement_in",
+           reason = "placement box design is still being worked out.",
+           issue = "27779")]
 impl<T> Placer<T> for ExchangeHeapSingleton {
     type Place = IntermediateBox<T>;
 
@@ -198,6 +210,9 @@ impl<T> Placer<T> for ExchangeHeapSingleton {
     }
 }
 
+#[unstable(feature = "placement_in",
+           reason = "placement box design is still being worked out.",
+           issue = "27779")]
 impl<T: ?Sized> Drop for IntermediateBox<T> {
     fn drop(&mut self) {
         if self.size > 0 {
@@ -221,7 +236,7 @@ impl<T> Box<T> {
     }
 }
 
-impl<T : ?Sized> Box<T> {
+impl<T: ?Sized> Box<T> {
     /// Constructs a box from the raw pointer.
     ///
     /// After this function call, pointer is owned by resulting box.
@@ -264,7 +279,6 @@ impl<T : ?Sized> Box<T> {
 
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<T: Default> Default for Box<T> {
-    #[stable(feature = "rust1", since = "1.0.0")]
     fn default() -> Box<T> {
         box Default::default()
     }
@@ -272,7 +286,6 @@ impl<T: Default> Default for Box<T> {
 
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<T> Default for Box<[T]> {
-    #[stable(feature = "rust1", since = "1.0.0")]
     fn default() -> Box<[T]> {
         Box::<[T; 0]>::new([])
     }
@@ -375,6 +388,13 @@ impl<T: ?Sized + Hash> Hash for Box<T> {
     }
 }
 
+#[stable(feature = "from_for_ptrs", since = "1.6.0")]
+impl<T> From<T> for Box<T> {
+    fn from(t: T) -> Self {
+        Box::new(t)
+    }
+}
+
 impl Box<Any> {
     #[inline]
     #[stable(feature = "rust1", since = "1.0.0")]
@@ -512,8 +532,8 @@ pub trait FnBox<A> {
     fn call_box(self: Box<Self>, args: A) -> Self::Output;
 }
 
-impl<A,F> FnBox<A> for F
-    where F: FnOnce<A>
+#[unstable(feature = "fnbox", reason = "Newly introduced", issue = "0")]
+impl<A, F> FnBox<A> for F where F: FnOnce<A>
 {
     type Output = F::Output;
 
@@ -522,7 +542,8 @@ impl<A,F> FnBox<A> for F
     }
 }
 
-impl<'a,A,R> FnOnce<A> for Box<FnBox<A,Output=R>+'a> {
+#[unstable(feature = "fnbox", reason = "Newly introduced", issue = "0")]
+impl<'a, A, R> FnOnce<A> for Box<FnBox<A, Output = R> + 'a> {
     type Output = R;
 
     extern "rust-call" fn call_once(self, args: A) -> R {
@@ -530,7 +551,8 @@ impl<'a,A,R> FnOnce<A> for Box<FnBox<A,Output=R>+'a> {
     }
 }
 
-impl<'a,A,R> FnOnce<A> for Box<FnBox<A,Output=R>+Send+'a> {
+#[unstable(feature = "fnbox", reason = "Newly introduced", issue = "0")]
+impl<'a, A, R> FnOnce<A> for Box<FnBox<A, Output = R> + Send + 'a> {
     type Output = R;
 
     extern "rust-call" fn call_once(self, args: A) -> R {
@@ -538,7 +560,8 @@ impl<'a,A,R> FnOnce<A> for Box<FnBox<A,Output=R>+Send+'a> {
     }
 }
 
-impl<T: ?Sized+Unsize<U>, U: ?Sized> CoerceUnsized<Box<U>> for Box<T> {}
+#[unstable(feature = "coerce_unsized", issue = "27732")]
+impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<Box<U>> for Box<T> {}
 
 #[stable(feature = "box_slice_clone", since = "1.3.0")]
 impl<T: Clone> Clone for Box<[T]> {
@@ -591,12 +614,14 @@ impl<T: Clone> Clone for Box<[T]> {
     }
 }
 
+#[stable(feature = "rust1", since = "1.0.0")]
 impl<T: ?Sized> borrow::Borrow<T> for Box<T> {
     fn borrow(&self) -> &T {
         &**self
     }
 }
 
+#[stable(feature = "rust1", since = "1.0.0")]
 impl<T: ?Sized> borrow::BorrowMut<T> for Box<T> {
     fn borrow_mut(&mut self) -> &mut T {
         &mut **self