]> git.lizzy.rs Git - rust.git/blobdiff - src/liballoc/boxed.rs
rollup merge of #23939: nikomatsakis/fn-box
[rust.git] / src / liballoc / boxed.rs
index 8e3be7dd05badafb9c4fe81d573c309010bff26a..2801cf38cb75529d94912551a60a5eab51597235 100644 (file)
 use core::any::Any;
 use core::cmp::Ordering;
 use core::default::Default;
-use core::error::Error;
 use core::fmt;
 use core::hash::{self, Hash};
 use core::mem;
 use core::ops::{Deref, DerefMut};
-use core::ptr::{self, Unique};
-use core::raw::{TraitObject, Slice};
-
-use heap;
+use core::ptr::{Unique};
+use core::raw::{TraitObject};
 
 /// A value that represents the heap. This is the default place that the `box`
 /// keyword allocates into when no place is supplied.
@@ -86,6 +83,7 @@
 /// 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>(Unique<T>);
 
 impl<T> Box<T> {
@@ -277,13 +275,6 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
     }
 }
 
-#[stable(feature = "rust1", since = "1.0.0")]
-impl fmt::Debug for Box<Any> {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        f.pad("Box<Any>")
-    }
-}
-
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<T: ?Sized> Deref for Box<T> {
     type Target = T;
@@ -309,52 +300,6 @@ fn next_back(&mut self) -> Option<I::Item> { (**self).next_back() }
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<I: ExactSizeIterator + ?Sized> ExactSizeIterator for Box<I> {}
 
-#[stable(feature = "rust1", since = "1.0.0")]
-impl<'a, E: Error + 'a> From<E> for Box<Error + 'a> {
-    fn from(err: E) -> Box<Error + 'a> {
-        Box::new(err)
-    }
-}
-
-#[stable(feature = "rust1", since = "1.0.0")]
-impl<'a, E: Error + Send + 'a> From<E> for Box<Error + Send + 'a> {
-    fn from(err: E) -> Box<Error + Send + 'a> {
-        Box::new(err)
-    }
-}
-
-#[stable(feature = "rust1", since = "1.0.0")]
-impl<'a, 'b> From<&'b str> for Box<Error + Send + 'a> {
-    fn from(err: &'b str) -> Box<Error + Send + 'a> {
-        #[derive(Debug)]
-        struct StringError(Box<str>);
-        impl Error for StringError {
-            fn description(&self) -> &str { &self.0 }
-        }
-        impl fmt::Display for StringError {
-            fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-                self.0.fmt(f)
-            }
-        }
-
-        // Unfortunately `String` is located in libcollections, so we construct
-        // a `Box<str>` manually here.
-        unsafe {
-            let alloc = if err.len() == 0 {
-                0 as *mut u8
-            } else {
-                let ptr = heap::allocate(err.len(), 1);
-                if ptr.is_null() { ::oom(); }
-                ptr as *mut u8
-            };
-            ptr::copy(err.as_bytes().as_ptr(), alloc, err.len());
-            Box::new(StringError(mem::transmute(Slice {
-                data: alloc,
-                len: err.len(),
-            })))
-        }
-    }
-}
 
 /// `FnBox` is a version of the `FnOnce` intended for use with boxed
 /// closure objects. The idea is that where one would normally store a