diff options
| author | bors <bors@rust-lang.org> | 2015-07-31 02:57:34 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-07-31 02:57:34 +0000 |
| commit | cb250b722e8c9c8b2e6dff249ce8e027dce2cd65 (patch) | |
| tree | d461b5e0dc9af3ffe4f051f31cd5b1450977130e /src/libstd | |
| parent | dc966ef95cf9c428b29e1346e54768f7411466c8 (diff) | |
| parent | 76db37ee4b916a678181b36e42c26d92524e7041 (diff) | |
| download | rust-cb250b722e8c9c8b2e6dff249ce8e027dce2cd65.tar.gz rust-cb250b722e8c9c8b2e6dff249ce8e027dce2cd65.zip | |
Auto merge of #27370 - alexcrichton:stabilize-easy, r=brson
The following APIs were all marked with a `#[stable]` tag:
* process::Child::id
* error::Error::is
* error::Error::downcast
* error::Error::downcast_ref
* error::Error::downcast_mut
* io::Error::get_ref
* io::Error::get_mut
* io::Error::into_inner
* hash::Hash::hash_slice
* hash::Hasher::write_{i,u}{8,16,32,64,size}
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/error.rs | 102 | ||||
| -rw-r--r-- | src/libstd/io/error.rs | 15 | ||||
| -rw-r--r-- | src/libstd/process.rs | 2 |
3 files changed, 100 insertions, 19 deletions
diff --git a/src/libstd/error.rs b/src/libstd/error.rs index b21b2edf2ec..4d08f08bb6e 100644 --- a/src/libstd/error.rs +++ b/src/libstd/error.rs @@ -168,7 +168,7 @@ impl Error for string::FromUtf16Error { // copied from any.rs impl Error + 'static { /// Returns true if the boxed type is the same as `T` - #[unstable(feature = "error_downcast", reason = "recently added")] + #[stable(feature = "error_downcast", since = "1.3.0")] #[inline] pub fn is<T: Error + 'static>(&self) -> bool { // Get TypeId of the type this function is instantiated with @@ -183,7 +183,7 @@ impl Error + 'static { /// Returns some reference to the boxed value if it is of type `T`, or /// `None` if it isn't. - #[unstable(feature = "error_downcast", reason = "recently added")] + #[stable(feature = "error_downcast", since = "1.3.0")] #[inline] pub fn downcast_ref<T: Error + 'static>(&self) -> Option<&T> { if self.is::<T>() { @@ -201,7 +201,7 @@ impl Error + 'static { /// Returns some mutable reference to the boxed value if it is of type `T`, or /// `None` if it isn't. - #[unstable(feature = "error_downcast", reason = "recently added")] + #[stable(feature = "error_downcast", since = "1.3.0")] #[inline] pub fn downcast_mut<T: Error + 'static>(&mut self) -> Option<&mut T> { if self.is::<T>() { @@ -220,21 +220,44 @@ impl Error + 'static { impl Error + 'static + Send { /// Forwards to the method defined on the type `Any`. - #[unstable(feature = "error_downcast", reason = "recently added")] + #[stable(feature = "error_downcast", since = "1.3.0")] #[inline] pub fn is<T: Error + 'static>(&self) -> bool { <Error + 'static>::is::<T>(self) } /// Forwards to the method defined on the type `Any`. - #[unstable(feature = "error_downcast", reason = "recently added")] + #[stable(feature = "error_downcast", since = "1.3.0")] #[inline] pub fn downcast_ref<T: Error + 'static>(&self) -> Option<&T> { <Error + 'static>::downcast_ref::<T>(self) } /// Forwards to the method defined on the type `Any`. - #[unstable(feature = "error_downcast", reason = "recently added")] + #[stable(feature = "error_downcast", since = "1.3.0")] + #[inline] + pub fn downcast_mut<T: Error + 'static>(&mut self) -> Option<&mut T> { + <Error + 'static>::downcast_mut::<T>(self) + } +} + +impl Error + 'static + Send + Sync { + /// Forwards to the method defined on the type `Any`. + #[stable(feature = "error_downcast", since = "1.3.0")] + #[inline] + pub fn is<T: Error + 'static>(&self) -> bool { + <Error + 'static>::is::<T>(self) + } + + /// Forwards to the method defined on the type `Any`. + #[stable(feature = "error_downcast", since = "1.3.0")] + #[inline] + pub fn downcast_ref<T: Error + 'static>(&self) -> Option<&T> { + <Error + 'static>::downcast_ref::<T>(self) + } + + /// Forwards to the method defined on the type `Any`. + #[stable(feature = "error_downcast", since = "1.3.0")] #[inline] pub fn downcast_mut<T: Error + 'static>(&mut self) -> Option<&mut T> { <Error + 'static>::downcast_mut::<T>(self) @@ -243,7 +266,7 @@ impl Error + 'static + Send { impl Error { #[inline] - #[unstable(feature = "error_downcast", reason = "recently added")] + #[stable(feature = "error_downcast", since = "1.3.0")] /// Attempt to downcast the box to a concrete type. pub fn downcast<T: Error + 'static>(self: Box<Self>) -> Result<Box<T>, Box<Error>> { if self.is::<T>() { @@ -264,9 +287,10 @@ impl Error { impl Error + Send { #[inline] - #[unstable(feature = "error_downcast", reason = "recently added")] + #[stable(feature = "error_downcast", since = "1.3.0")] /// Attempt to downcast the box to a concrete type. - pub fn downcast<T: Error + 'static>(self: Box<Self>) -> Result<Box<T>, Box<Error + Send>> { + pub fn downcast<T: Error + 'static>(self: Box<Self>) + -> Result<Box<T>, Box<Error + Send>> { let err: Box<Error> = self; <Error>::downcast(err).map_err(|s| unsafe { // reapply the Send marker @@ -274,3 +298,63 @@ impl Error + Send { }) } } + +impl Error + Send + Sync { + #[inline] + #[stable(feature = "error_downcast", since = "1.3.0")] + /// Attempt to downcast the box to a concrete type. + pub fn downcast<T: Error + 'static>(self: Box<Self>) + -> Result<Box<T>, Box<Self>> { + let err: Box<Error> = self; + <Error>::downcast(err).map_err(|s| unsafe { + // reapply the Send+Sync marker + transmute::<Box<Error>, Box<Error + Send + Sync>>(s) + }) + } +} + +#[cfg(test)] +mod tests { + use prelude::v1::*; + use super::Error; + use fmt; + + #[derive(Debug, PartialEq)] + struct A; + #[derive(Debug, PartialEq)] + struct B; + + impl fmt::Display for A { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "A") + } + } + impl fmt::Display for B { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "B") + } + } + + impl Error for A { + fn description(&self) -> &str { "A-desc" } + } + impl Error for B { + fn description(&self) -> &str { "A-desc" } + } + + #[test] + fn downcasting() { + let mut a = A; + let mut a = &mut a as &mut (Error + 'static); + assert_eq!(a.downcast_ref::<A>(), Some(&A)); + assert_eq!(a.downcast_ref::<B>(), None); + assert_eq!(a.downcast_mut::<A>(), Some(&mut A)); + assert_eq!(a.downcast_mut::<B>(), None); + + let a: Box<Error> = Box::new(A); + match a.downcast::<B>() { + Ok(..) => panic!("expected error"), + Err(e) => assert_eq!(*e.downcast::<A>().unwrap(), A), + } + } +} diff --git a/src/libstd/io/error.rs b/src/libstd/io/error.rs index 3b48ff30960..e12e202148b 100644 --- a/src/libstd/io/error.rs +++ b/src/libstd/io/error.rs @@ -219,8 +219,7 @@ impl Error { /// /// If this `Error` was constructed via `new` then this function will /// return `Some`, otherwise it will return `None`. - #[unstable(feature = "io_error_inner", - reason = "recently added and requires UFCS to downcast")] + #[stable(feature = "io_error_inner", since = "1.3.0")] pub fn get_ref(&self) -> Option<&(error::Error+Send+Sync+'static)> { match self.repr { Repr::Os(..) => None, @@ -233,8 +232,7 @@ impl Error { /// /// If this `Error` was constructed via `new` then this function will /// return `Some`, otherwise it will return `None`. - #[unstable(feature = "io_error_inner", - reason = "recently added and requires UFCS to downcast")] + #[stable(feature = "io_error_inner", since = "1.3.0")] pub fn get_mut(&mut self) -> Option<&mut (error::Error+Send+Sync+'static)> { match self.repr { Repr::Os(..) => None, @@ -246,8 +244,7 @@ impl Error { /// /// If this `Error` was constructed via `new` then this function will /// return `Some`, otherwise it will return `None`. - #[unstable(feature = "io_error_inner", - reason = "recently added and requires UFCS to downcast")] + #[stable(feature = "io_error_inner", since = "1.3.0")] pub fn into_inner(self) -> Option<Box<error::Error+Send+Sync>> { match self.repr { Repr::Os(..) => None, @@ -349,10 +346,10 @@ mod test { // we have to call all of these UFCS style right now since method // resolution won't implicitly drop the Send+Sync bounds let mut err = Error::new(ErrorKind::Other, TestError); - assert!(error::Error::is::<TestError>(err.get_ref().unwrap())); + assert!(err.get_ref().unwrap().is::<TestError>()); assert_eq!("asdf", err.get_ref().unwrap().description()); - assert!(error::Error::is::<TestError>(err.get_mut().unwrap())); + assert!(err.get_mut().unwrap().is::<TestError>()); let extracted = err.into_inner().unwrap(); - error::Error::downcast::<TestError>(extracted).unwrap(); + extracted.downcast::<TestError>().unwrap(); } } diff --git a/src/libstd/process.rs b/src/libstd/process.rs index fefd7bb051f..74a66558627 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -505,7 +505,7 @@ impl Child { } /// Returns the OS-assigned process identifier associated with this child. - #[unstable(feature = "process_id", reason = "api recently added")] + #[stable(feature = "process_id", since = "1.3.0")] pub fn id(&self) -> u32 { self.handle.id() } |
