Move trait bounds to where-clauses
Before adoption: this commit came in with the history the project adopted, so no landing records it.
I find it more readable how this appears in rustdoc.
authored by David Tolnay · committed by David Tolnay · parent 8da8c97 · Browse files · 3 files·+69 added−18 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+69 added−18 removed
- other:+69 added−18 removed
Provenance
- Commit
7dcc851- Tree
eb4a5bc- Author
David Tolnay <dtolnay@gmail.com>- Committer
David Tolnay <dtolnay@gmail.com>- Parent
8da8c97
3 files changed+69 added−18 removed
modified:src/as_error.rs+4 added-1 removed
6 unmodified lines7 /// View type as an error object.8 fn as_error(&self) -> &(dyn StdError + Send + Sync + 'static);9 }10 11-impl<T: StdError + Send + Sync + 'static> AsError for T {11+impl<T> AsError for T12+where13+ T: StdError + Send + Sync + 'static,14+{15 fn as_error(&self) -> &(dyn StdError + Send + Sync + 'static) {16 self17 }18 }12 unmodified linesmodified:src/context.rs+33 added-8 removed
5 unmodified lines6 7 /// Provides the `context` method for `Result`.8 pub trait Context<T, E> {9 /// Wrap the error value with additional context.10- fn context<C: Display + Send + Sync + 'static>(self, context: C) -> Result<T, Error>;10+ fn context<C>(self, context: C) -> Result<T, Error>11+ where12+ C: Display + Send + Sync + 'static;13 14 /// Wrap the error value with additional context lazily.15 fn with_context<C, F>(self, f: F) -> Result<T, Error>16 where17 C: Display + Send + Sync + 'static,18 F: FnOnce(&E) -> C;19 }20 19-impl<T, E: StdError + Send + Sync + 'static> Context<T, E> for Result<T, E> {20- fn context<C: Display + Send + Sync + 'static>(self, context: C) -> Result<T, Error> {21+impl<T, E> Context<T, E> for Result<T, E>22+where23+ E: StdError + Send + Sync + 'static,24+{25+ fn context<C>(self, context: C) -> Result<T, Error>26+ where27+ C: Display + Send + Sync + 'static,28+ {29 self.map_err(|error| Error::from(ContextError { error, context }))30 }31 32 fn with_context<C, F>(self, f: F) -> Result<T, Error>10 unmodified lines43 }44 }45 46 impl<T> Context<T, Error> for Result<T, Error> {39- fn context<C: Display + Send + Sync + 'static>(self, context: C) -> Result<T, Error> {47+ fn context<C>(self, context: C) -> Result<T, Error>48+ where49+ C: Display + Send + Sync + 'static,50+ {51 self.map_err(|error| Error::from(ContextError { error, context }))52 }53 54 fn with_context<C, F>(self, f: F) -> Result<T, Error>14 unmodified lines69 error: E,70 context: C,71 }72 62-impl<E: Debug, C: Display> Debug for ContextError<E, C> {73+impl<E, C> Debug for ContextError<E, C>74+where75+ E: Debug,76+ C: Display,77+{78 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {79 write!(f, "{:?}\n\n{}", self.error, self.context)80 }81 }82 68-impl<E, C: Display> Display for ContextError<E, C> {83+impl<E, C> Display for ContextError<E, C>84+where85+ C: Display,86+{87 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {88 Display::fmt(&self.context, f)89 }90 }91 74-impl<E: StdError + 'static, C: Display> StdError for ContextError<E, C> {92+impl<E, C> StdError for ContextError<E, C>93+where94+ E: StdError + 'static,95+ C: Display,96+{97 fn backtrace(&self) -> Option<&Backtrace> {98 self.error.backtrace()99 }100 5 unmodified lines106 Some(&self.error)107 }108 }109 88-impl<C: Display> StdError for ContextError<Error, C> {110+impl<C> StdError for ContextError<Error, C>111+where112+ C: Display,113+{114 fn backtrace(&self) -> Option<&Backtrace> {115 Some(self.error.backtrace())116 }117 8 unmodified linesmodified:src/error.rs+32 added-9 removed
98 unmodified lines99 }100 }101 102 /// Returns `true` if `E` is the type wrapped by this error object.103- pub fn is<E: Display + Debug + Send + Sync + 'static>(&self) -> bool {103+ pub fn is<E>(&self) -> bool104+ where105+ E: Display + Debug + Send + Sync + 'static,106+ {107 TypeId::of::<E>() == self.inner.type_id108 }109 110 /// Attempt to downcast the error object to a concrete type.108- pub fn downcast<E: Display + Debug + Send + Sync + 'static>(self) -> Result<E, Error> {111+ pub fn downcast<E>(self) -> Result<E, Error>112+ where113+ E: Display + Debug + Send + Sync + 'static,114+ {115 if let Some(error) = self.downcast_ref::<E>() {116 unsafe {117 let error = ptr::read(error);118 drop(ptr::read(&self.inner));5 unmodified lines124 }125 }126 127 /// Downcast this error object by reference.122- pub fn downcast_ref<E: Display + Debug + Send + Sync + 'static>(&self) -> Option<&E> {128+ pub fn downcast_ref<E>(&self) -> Option<&E>129+ where130+ E: Display + Debug + Send + Sync + 'static,131+ {132 if self.is::<E>() {133 unsafe { Some(&*(self.inner.error() as *const dyn StdError as *const E)) }134 } else {135 None136 }137 }138 139 /// Downcast this error object by mutable reference.131- pub fn downcast_mut<E: Display + Debug + Send + Sync + 'static>(&mut self) -> Option<&mut E> {140+ pub fn downcast_mut<E>(&mut self) -> Option<&mut E>141+ where142+ E: Display + Debug + Send + Sync + 'static,143+ {144 if self.is::<E>() {145 unsafe { Some(&mut *(self.inner.error_mut() as *mut dyn StdError as *mut E)) }146 } else {147 None148 }149 }150 }151 140-impl<E: StdError + Send + Sync + 'static> From<E> for Error {152+impl<E> From<E> for Error153+where154+ E: StdError + Send + Sync + 'static,155+{156 fn from(error: E) -> Error {157 Error::new(error)158 }159 }75 unmodified lines235 vtable: *const (),236 }237 238 #[repr(transparent)]224-struct MessageError<M: Display + Debug>(M);239+struct MessageError<M>(M)240+where241+ M: Display + Debug;242 226-impl<M: Display + Debug> Debug for MessageError<M> {243+impl<M> Debug for MessageError<M>244+where245+ M: Display + Debug,246+{247 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {248 Debug::fmt(&self.0, f)249 }250 }251 232-impl<M: Display + Debug> Display for MessageError<M> {252+impl<M> Display for MessageError<M>253+where254+ M: Display + Debug,255+{256 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {257 Display::fmt(&self.0, f)258 }259 }260 238-impl<M: Display + Debug + 'static> StdError for MessageError<M> {}261+impl<M> StdError for MessageError<M> where M: Display + Debug + 'static {}262 263 impl ErrorImpl<()> {264 fn error(&self) -> &(dyn StdError + Send + Sync + 'static) {265 unsafe {78 unmodified lines