diff options
| author | Mark Rousskov <mark.simulacrum@gmail.com> | 2019-12-22 17:42:04 -0500 |
|---|---|---|
| committer | Mark Rousskov <mark.simulacrum@gmail.com> | 2019-12-22 17:42:47 -0500 |
| commit | a06baa56b95674fc626b3c3fd680d6a65357fe60 (patch) | |
| tree | cd9d867c2ca3cff5c1d6b3bd73377c44649fb075 /src/libstd/error.rs | |
| parent | 8eb7c58dbb7b32701af113bc58722d0d1fefb1eb (diff) | |
| download | rust-a06baa56b95674fc626b3c3fd680d6a65357fe60.tar.gz rust-a06baa56b95674fc626b3c3fd680d6a65357fe60.zip | |
Format the world
Diffstat (limited to 'src/libstd/error.rs')
| -rw-r--r-- | src/libstd/error.rs | 88 |
1 files changed, 53 insertions, 35 deletions
diff --git a/src/libstd/error.rs b/src/libstd/error.rs index d4c4cb9c3b9..18ebd0f1a67 100644 --- a/src/libstd/error.rs +++ b/src/libstd/error.rs @@ -15,7 +15,7 @@ use core::array; -use crate::alloc::{AllocErr, LayoutErr, CannotReallocInPlace}; +use crate::alloc::{AllocErr, CannotReallocInPlace, LayoutErr}; use crate::any::TypeId; use crate::backtrace::Backtrace; use crate::borrow::Cow; @@ -130,8 +130,11 @@ pub trait Error: Debug + Display { /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_deprecated(since = "1.33.0", reason = "replaced by Error::source, which can support \ - downcasting")] + #[rustc_deprecated( + since = "1.33.0", + reason = "replaced by Error::source, which can support \ + downcasting" + )] fn cause(&self) -> Option<&dyn Error> { self.source() } @@ -195,14 +198,21 @@ pub trait Error: Debug + Display { /// } /// ``` #[stable(feature = "error_source", since = "1.30.0")] - fn source(&self) -> Option<&(dyn Error + 'static)> { None } + fn source(&self) -> Option<&(dyn Error + 'static)> { + None + } /// Gets the `TypeId` of `self`. #[doc(hidden)] - #[unstable(feature = "error_type_id", - reason = "this is memory-unsafe to override in user code", - issue = "60784")] - fn type_id(&self, _: private::Internal) -> TypeId where Self: 'static { + #[unstable( + feature = "error_type_id", + reason = "this is memory-unsafe to override in user code", + issue = "60784" + )] + fn type_id(&self, _: private::Internal) -> TypeId + where + Self: 'static, + { TypeId::of::<Self>() } @@ -332,7 +342,9 @@ impl From<String> for Box<dyn Error + Send + Sync> { struct StringError(String); impl Error for StringError { - fn description(&self) -> &str { &self.0 } + fn description(&self) -> &str { + &self.0 + } } impl Display for StringError { @@ -467,30 +479,38 @@ impl<'a> From<Cow<'a, str>> for Box<dyn Error> { #[unstable(feature = "never_type", issue = "35121")] impl Error for ! { - fn description(&self) -> &str { *self } + fn description(&self) -> &str { + *self + } } -#[unstable(feature = "allocator_api", - reason = "the precise API and guarantees it provides may be tweaked.", - issue = "32838")] +#[unstable( + feature = "allocator_api", + reason = "the precise API and guarantees it provides may be tweaked.", + issue = "32838" +)] impl Error for AllocErr { fn description(&self) -> &str { "memory allocation failed" } } -#[unstable(feature = "allocator_api", - reason = "the precise API and guarantees it provides may be tweaked.", - issue = "32838")] +#[unstable( + feature = "allocator_api", + reason = "the precise API and guarantees it provides may be tweaked.", + issue = "32838" +)] impl Error for LayoutErr { fn description(&self) -> &str { "invalid parameters to Layout::from_size_align" } } -#[unstable(feature = "allocator_api", - reason = "the precise API and guarantees it provides may be tweaked.", - issue = "32838")] +#[unstable( + feature = "allocator_api", + reason = "the precise API and guarantees it provides may be tweaked.", + issue = "32838" +)] impl Error for CannotReallocInPlace { fn description(&self) -> &str { CannotReallocInPlace::description(self) @@ -499,7 +519,9 @@ impl Error for CannotReallocInPlace { #[stable(feature = "rust1", since = "1.0.0")] impl Error for str::ParseBoolError { - fn description(&self) -> &str { "failed to parse bool" } + fn description(&self) -> &str { + "failed to parse bool" + } } #[stable(feature = "rust1", since = "1.0.0")] @@ -638,9 +660,7 @@ impl dyn Error + 'static { #[inline] pub fn downcast_ref<T: Error + 'static>(&self) -> Option<&T> { if self.is::<T>() { - unsafe { - Some(&*(self as *const dyn Error as *const T)) - } + unsafe { Some(&*(self as *const dyn Error as *const T)) } } else { None } @@ -652,9 +672,7 @@ impl dyn Error + 'static { #[inline] pub fn downcast_mut<T: Error + 'static>(&mut self) -> Option<&mut T> { if self.is::<T>() { - unsafe { - Some(&mut *(self as *mut dyn Error as *mut T)) - } + unsafe { Some(&mut *(self as *mut dyn Error as *mut T)) } } else { None } @@ -778,9 +796,7 @@ impl dyn Error { #[unstable(feature = "error_iter", issue = "58520")] #[inline] pub fn chain(&self) -> Chain<'_> { - Chain { - current: Some(self), - } + Chain { current: Some(self) } } } @@ -811,8 +827,7 @@ impl dyn Error + Send { #[inline] #[stable(feature = "error_downcast", since = "1.3.0")] /// Attempts to downcast the box to a concrete type. - pub fn downcast<T: Error + 'static>(self: Box<Self>) - -> Result<Box<T>, Box<dyn Error + Send>> { + pub fn downcast<T: Error + 'static>(self: Box<Self>) -> Result<Box<T>, Box<dyn Error + Send>> { let err: Box<dyn Error> = self; <dyn Error>::downcast(err).map_err(|s| unsafe { // Reapply the `Send` marker. @@ -825,8 +840,7 @@ impl dyn Error + Send + Sync { #[inline] #[stable(feature = "error_downcast", since = "1.3.0")] /// Attempts to downcast the box to a concrete type. - pub fn downcast<T: Error + 'static>(self: Box<Self>) - -> Result<Box<T>, Box<Self>> { + pub fn downcast<T: Error + 'static>(self: Box<Self>) -> Result<Box<T>, Box<Self>> { let err: Box<dyn Error> = self; <dyn Error>::downcast(err).map_err(|s| unsafe { // Reapply the `Send + Sync` marker. @@ -857,10 +871,14 @@ mod tests { } impl Error for A { - fn description(&self) -> &str { "A-desc" } + fn description(&self) -> &str { + "A-desc" + } } impl Error for B { - fn description(&self) -> &str { "A-desc" } + fn description(&self) -> &str { + "A-desc" + } } #[test] |
