diff options
| author | Fenrir <[email protected]> | 2018-01-21 14:06:28 -0700 |
|---|---|---|
| committer | FenrirWolf <[email protected]> | 2018-01-21 19:16:33 -0700 |
| commit | 23be3f4885688e5e0011005e2295c75168854c0a (patch) | |
| tree | dd0850f9c73c489e114a761d5c0757f3dbec3a65 /ctr-std/src/error.rs | |
| parent | Update CI for Rust nightly-2017-12-01 + other fixes (diff) | |
| download | ctru-rs-23be3f4885688e5e0011005e2295c75168854c0a.tar.xz ctru-rs-23be3f4885688e5e0011005e2295c75168854c0a.zip | |
Recreate ctr-std from latest nightly
Diffstat (limited to 'ctr-std/src/error.rs')
| -rw-r--r-- | ctr-std/src/error.rs | 75 |
1 files changed, 69 insertions, 6 deletions
diff --git a/ctr-std/src/error.rs b/ctr-std/src/error.rs index 454fa47..eb5022a 100644 --- a/ctr-std/src/error.rs +++ b/ctr-std/src/error.rs @@ -51,9 +51,13 @@ // coherence challenge (e.g., specialization, neg impls, etc) we can // reconsider what crate these items belong in. +use alloc::allocator; use any::TypeId; +use borrow::Cow; use cell; use char; +use convert; +use core::array; use fmt::{self, Debug, Display}; use mem::transmute; use num; @@ -109,7 +113,7 @@ pub trait Error: Debug + Display { /// /// impl Error for SuperError { /// fn description(&self) -> &str { - /// "I'm the superhero of errors!" + /// "I'm the superhero of errors" /// } /// /// fn cause(&self) -> Option<&Error> { @@ -128,7 +132,7 @@ pub trait Error: Debug + Display { /// /// impl Error for SuperErrorSideKick { /// fn description(&self) -> &str { - /// "I'm SuperError side kick!" + /// "I'm SuperError side kick" /// } /// } /// @@ -193,7 +197,7 @@ impl From<String> for Box<Error + Send + Sync> { } } -#[stable(feature = "string_box_error", since = "1.7.0")] +#[stable(feature = "string_box_error", since = "1.6.0")] impl From<String> for Box<Error> { fn from(str_err: String) -> Box<Error> { let err1: Box<Error + Send + Sync> = From::from(str_err); @@ -209,13 +213,50 @@ impl<'a, 'b> From<&'b str> for Box<Error + Send + Sync + 'a> { } } -#[stable(feature = "string_box_error", since = "1.7.0")] +#[stable(feature = "string_box_error", since = "1.6.0")] impl<'a> From<&'a str> for Box<Error> { fn from(err: &'a str) -> Box<Error> { From::from(String::from(err)) } } +#[stable(feature = "cow_box_error", since = "1.22.0")] +impl<'a, 'b> From<Cow<'b, str>> for Box<Error + Send + Sync + 'a> { + fn from(err: Cow<'b, str>) -> Box<Error + Send + Sync + 'a> { + From::from(String::from(err)) + } +} + +#[stable(feature = "cow_box_error", since = "1.22.0")] +impl<'a> From<Cow<'a, str>> for Box<Error> { + fn from(err: Cow<'a, str>) -> Box<Error> { + From::from(String::from(err)) + } +} + +#[unstable(feature = "never_type", issue = "35121")] +impl Error for ! { + fn description(&self) -> &str { *self } +} + +#[unstable(feature = "allocator_api", + reason = "the precise API and guarantees it provides may be tweaked.", + issue = "32838")] +impl Error for allocator::AllocErr { + fn description(&self) -> &str { + allocator::AllocErr::description(self) + } +} + +#[unstable(feature = "allocator_api", + reason = "the precise API and guarantees it provides may be tweaked.", + issue = "32838")] +impl Error for allocator::CannotReallocInPlace { + fn description(&self) -> &str { + allocator::CannotReallocInPlace::description(self) + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl Error for str::ParseBoolError { fn description(&self) -> &str { "failed to parse bool" } @@ -242,6 +283,13 @@ impl Error for num::TryFromIntError { } } +#[unstable(feature = "try_from", issue = "33417")] +impl Error for array::TryFromSliceError { + fn description(&self) -> &str { + self.__description() + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl Error for num::ParseFloatError { fn description(&self) -> &str { @@ -277,7 +325,7 @@ impl Error for char::DecodeUtf16Error { } } -#[stable(feature = "box_error", since = "1.7.0")] +#[stable(feature = "box_error", since = "1.8.0")] impl<T: Error> Error for Box<T> { fn description(&self) -> &str { Error::description(&**self) @@ -316,6 +364,21 @@ impl Error for char::CharTryFromError { } } +#[stable(feature = "char_from_str", since = "1.20.0")] +impl Error for char::ParseCharError { + fn description(&self) -> &str { + self.__description() + } +} + +#[unstable(feature = "try_from", issue = "33417")] +impl Error for convert::Infallible { + fn description(&self) -> &str { + match *self { + } + } +} + // copied from any.rs impl Error + 'static { /// Returns true if the boxed type is the same as `T` @@ -482,7 +545,7 @@ mod tests { #[test] fn downcasting() { let mut a = A; - let mut a = &mut a as &mut (Error + 'static); + let 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)); |