diff options
| author | bors <bors@rust-lang.org> | 2019-12-23 02:47:52 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-12-23 02:47:52 +0000 |
| commit | a916ac22b9f7f1f0f7aba0a41a789b3ecd765018 (patch) | |
| tree | 139cba4184f0f290fdbdff1aa0aa68352b16ccbb /src/libstd/error.rs | |
| parent | 9b98af84c4aa66392236fff59c86da2130d46d46 (diff) | |
| parent | 0f24ccd21d9f734a21daaf3566900127167556d1 (diff) | |
| download | rust-a916ac22b9f7f1f0f7aba0a41a789b3ecd765018.tar.gz rust-a916ac22b9f7f1f0f7aba0a41a789b3ecd765018.zip | |
Auto merge of #67540 - Mark-Simulacrum:fmt-the-world, r=Centril
Format the world This PR modifies the formatting infrastructure a bit in the first commit (to enable the forgotten 2018 edition), as well as removes most directories from the ignore list in rustfmt.toml. It then follows that up with the second commit which runs `x.py fmt` and formats the entire repository. We continue to not format the test directory (`src/test`) because of interactions with pretty printing and, in part, because re-blessing all of those files is somewhat harder to review, so is best suited for a follow up PR in my opinion.
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] |
