]> git.lizzy.rs Git - rust.git/blobdiff - src/liballoc/boxed.rs
std: Rename Show/String to Debug/Display
[rust.git] / src / liballoc / boxed.rs
index 458eb3dce57a80f5bcf48fa06e601f6ceaa79181..c2ee1a5d024c4ab4a755cf195a3f92aa8daa6cb6 100644 (file)
 use core::clone::Clone;
 use core::cmp::{PartialEq, PartialOrd, Eq, Ord, Ordering};
 use core::default::Default;
+use core::error::{Error, FromError};
 use core::fmt;
 use core::hash::{self, Hash};
 use core::marker::Sized;
 use core::mem;
+use core::ops::{Deref, DerefMut};
 use core::option::Option;
 use core::ptr::Unique;
 use core::raw::TraitObject;
-use core::result::Result;
 use core::result::Result::{Ok, Err};
-use core::ops::{Deref, DerefMut};
+use core::result::Result;
 
 /// A value that represents the global exchange heap. This is the default
 /// place that the `box` keyword allocates into when no place is supplied.
@@ -117,14 +118,6 @@ fn cmp(&self, other: &Box<T>) -> Ordering {
 #[stable]
 impl<T: ?Sized + Eq> Eq for Box<T> {}
 
-#[cfg(stage0)]
-impl<S: hash::Writer, T: ?Sized + Hash<S>> Hash<S> for Box<T> {
-    #[inline]
-    fn hash(&self, state: &mut S) {
-        (**self).hash(state);
-    }
-}
-#[cfg(not(stage0))]
 impl<S: hash::Hasher, T: ?Sized + Hash<S>> Hash<S> for Box<T> {
     #[inline]
     fn hash(&self, state: &mut S) {
@@ -133,8 +126,11 @@ fn hash(&self, state: &mut S) {
 }
 
 /// Extension methods for an owning `Any` trait object.
-#[unstable = "post-DST and coherence changes, this will not be a trait but \
-              rather a direct `impl` on `Box<Any>`"]
+#[unstable = "this trait will likely disappear once compiler bugs blocking \
+              a direct impl on `Box<Any>` have been fixed "]
+// FIXME(#18737): this should be a direct impl on `Box<Any>`. If you're
+//                removing this please make sure that you can downcase on
+//                `Box<Any + Send>` as well as `Box<Any>`
 pub trait BoxAny {
     /// Returns the boxed value if it is of type `T`, or
     /// `Err(Self)` if it isn't.
@@ -142,10 +138,9 @@ pub trait BoxAny {
     fn downcast<T: 'static>(self) -> Result<Box<T>, Self>;
 }
 
+#[stable]
 impl BoxAny for Box<Any> {
     #[inline]
-    #[unstable = "method may be renamed with respect to other downcasting \
-                  methods"]
     fn downcast<T: 'static>(self) -> Result<Box<T>, Box<Any>> {
         if self.is::<T>() {
             unsafe {
@@ -162,20 +157,22 @@ fn downcast<T: 'static>(self) -> Result<Box<T>, Box<Any>> {
     }
 }
 
-impl<T: ?Sized + fmt::Show> fmt::Show for Box<T> {
+#[stable]
+impl<T: fmt::Display + ?Sized> fmt::Display for Box<T> {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        write!(f, "Box({:?})", &**self)
+        fmt::Display::fmt(&**self, f)
     }
 }
 
 #[stable]
-impl<T: ?Sized + fmt::String> fmt::String for Box<T> {
+impl<T: fmt::Debug + ?Sized> fmt::Debug for Box<T> {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        fmt::String::fmt(&**self, f)
+        fmt::Debug::fmt(&**self, f)
     }
 }
 
-impl fmt::Show for Box<Any> {
+#[stable]
+impl fmt::Debug for Box<Any> {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         f.pad("Box<Any>")
     }
@@ -193,6 +190,12 @@ impl<T: ?Sized> DerefMut for Box<T> {
     fn deref_mut(&mut self) -> &mut T { &mut **self }
 }
 
+impl<'a, E: Error + 'a> FromError<E> for Box<Error + 'a> {
+    fn from_error(err: E) -> Box<Error + 'a> {
+        Box::new(err)
+    }
+}
+
 #[cfg(test)]
 mod test {
     #[test]