Import std::error::Error as StdError
Before adoption: this commit came in with the history the project adopted, so no landing records it.
To avoid name collisions when renaming Exception to Error.
authored by David Tolnay · committed by David Tolnay · parent 2000930 · Browse files · 3 files·+31 added−31 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+31 added−31 removed
- other:+31 added−31 removed
Provenance
- Commit
7afc190- Tree
98b4dd3- Author
David Tolnay <dtolnay@gmail.com>- Committer
David Tolnay <dtolnay@gmail.com>- Parent
2000930
3 files changed+31 added−31 removed
modified:src/as_error.rs+7 added-7 removed
1-use std::error::Error;1+use std::error::Error as StdError;2 3 use crate::Exception;4 5 /// View type as an error object.6 pub trait AsError {7 /// View type as an error object.8- fn as_error(&self) -> &(dyn Error + Send + Sync + 'static);8+ fn as_error(&self) -> &(dyn StdError + Send + Sync + 'static);9 }10 11-impl<T: Error + Send + Sync + 'static> AsError for T {12- fn as_error(&self) -> &(dyn Error + Send + Sync + 'static) {11+impl<T: StdError + Send + Sync + 'static> AsError for T {12+ fn as_error(&self) -> &(dyn StdError + Send + Sync + 'static) {13 self14 }15 }16 17-impl AsError for dyn Error + Send + Sync + 'static {18- fn as_error(&self) -> &(dyn Error + Send + Sync + 'static) {17+impl AsError for dyn StdError + Send + Sync + 'static {18+ fn as_error(&self) -> &(dyn StdError + Send + Sync + 'static) {19 self20 }21 }22 23 impl AsError for Exception {24- fn as_error(&self) -> &(dyn Error + Send + Sync + 'static) {24+ fn as_error(&self) -> &(dyn StdError + Send + Sync + 'static) {25 &**self26 }27 }modified:src/context.rs+8 added-8 removed
1 use std::backtrace::Backtrace;2-use std::error::Error;2+use std::error::Error as StdError;3 use std::fmt::{self, Debug, Display};4 5 use crate::Exception;6 8 unmodified lines15 C: Display + Send + Sync + 'static,16 F: FnOnce(&E) -> C;17 }18 19-impl<T, E: Error + Send + Sync + 'static> Context<T, E> for Result<T, E> {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, Exception> {21 self.map_err(|error| Exception::from(ContextError { error, context }))22 }23 46 unmodified lines70 Display::fmt(&self.context, f)71 }72 }73 74-impl<E: Error + 'static, C: Display> Error for ContextError<E, C> {74+impl<E: StdError + 'static, C: Display> StdError for ContextError<E, C> {75 fn backtrace(&self) -> Option<&Backtrace> {76 self.error.backtrace()77 }78 79- fn cause(&self) -> Option<&dyn Error> {79+ fn cause(&self) -> Option<&dyn StdError> {80 Some(&self.error)81 }82 83- fn source(&self) -> Option<&(dyn Error + 'static)> {83+ fn source(&self) -> Option<&(dyn StdError + 'static)> {84 Some(&self.error)85 }86 }87 88-impl<C: Display> Error for ContextError<Exception, C> {88+impl<C: Display> StdError for ContextError<Exception, C> {89 fn backtrace(&self) -> Option<&Backtrace> {90 Some(self.error.backtrace())91 }92 93- fn cause(&self) -> Option<&dyn Error> {93+ fn cause(&self) -> Option<&dyn StdError> {94 Some(&*self.error)95 }96 97- fn source(&self) -> Option<&(dyn Error + 'static)> {97+ fn source(&self) -> Option<&(dyn StdError + 'static)> {98 Some(&*self.error)99 }100 }modified:src/error.rs+16 added-16 removed
1 use std::any::TypeId;2 use std::backtrace::{Backtrace, BacktraceStatus};3-use std::error::Error;3+use std::error::Error as StdError;4 use std::fmt::{self, Debug, Display};5 use std::mem;6 use std::ops::{Deref, DerefMut};7 use std::ptr;19 unmodified lines27 /// If the error type does not provide a backtrace, a backtrace will be created here to ensure28 /// that a backtrace exists.29 pub fn new<E>(error: E) -> Exception30 where31- E: Error + Send + Sync + 'static,31+ E: StdError + Send + Sync + 'static,32 {33 Exception::construct(error, TypeId::of::<E>())34 }35 6 unmodified lines42 }43 44 fn construct<E>(error: E, type_id: TypeId) -> Exception45 where46- E: Error + Send + Sync + 'static,46+ E: StdError + Send + Sync + 'static,47 {48 unsafe {49 let backtrace = match error.backtrace() {50 Some(_) => None,51 None => Some(Backtrace::capture()),52 };53- let obj: TraitObject = mem::transmute(&error as &dyn Error);53+ let obj: TraitObject = mem::transmute(&error as &dyn StdError);54 let vtable = obj.vtable;55 let inner = InnerException {56 vtable,57 type_id,6 unmodified lines64 }65 }66 67 /// View this exception as the underlying error.68- pub fn as_error(&self) -> &(dyn Error + Send + Sync + 'static) {68+ pub fn as_error(&self) -> &(dyn StdError + Send + Sync + 'static) {69 &**self70 }71 72 /// View this exception as the underlying error, mutably.73- pub fn as_error_mut(&mut self) -> &mut (dyn Error + Send + Sync + 'static) {73+ pub fn as_error_mut(&mut self) -> &mut (dyn StdError + Send + Sync + 'static) {74 &mut **self75 }76 77 /// Get the backtrace for this Exception.38 unmodified lines116 117 /// Downcast this exception by reference.118 pub fn downcast_ref<E: Display + Debug + Send + Sync + 'static>(&self) -> Option<&E> {119 if self.is::<E>() {120- unsafe { Some(&*(self.inner.error() as *const dyn Error as *const E)) }120+ unsafe { Some(&*(self.inner.error() as *const dyn StdError as *const E)) }121 } else {122 None123 }124 }125 126 /// Downcast this exception by mutable reference.127 pub fn downcast_mut<E: Display + Debug + Send + Sync + 'static>(&mut self) -> Option<&mut E> {128 if self.is::<E>() {129- unsafe { Some(&mut *(self.inner.error_mut() as *mut dyn Error as *mut E)) }129+ unsafe { Some(&mut *(self.inner.error_mut() as *mut dyn StdError as *mut E)) }130 } else {131 None132 }133 }134 }135 136-impl<E: Error + Send + Sync + 'static> From<E> for Exception {136+impl<E: StdError + Send + Sync + 'static> From<E> for Exception {137 fn from(error: E) -> Exception {138 Exception::new(error)139 }140 }141 142 impl Deref for Exception {143- type Target = dyn Error + Send + Sync + 'static;143+ type Target = dyn StdError + Send + Sync + 'static;144 fn deref(&self) -> &Self::Target {145 self.inner.error()146 }147 }83 unmodified lines231 Display::fmt(&self.0, f)232 }233 }234 235-impl<M: Display + Debug + 'static> Error for MessageError<M> {}235+impl<M: Display + Debug + 'static> StdError for MessageError<M> {}236 237 impl InnerException<()> {238- fn error(&self) -> &(dyn Error + Send + Sync + 'static) {238+ fn error(&self) -> &(dyn StdError + Send + Sync + 'static) {239 unsafe {240 mem::transmute(TraitObject {241 data: &self.error,242 vtable: self.vtable,243 })244 }245 }246 247- fn error_mut(&mut self) -> &mut (dyn Error + Send + Sync + 'static) {247+ fn error_mut(&mut self) -> &mut (dyn StdError + Send + Sync + 'static) {248 unsafe {249 mem::transmute(TraitObject {250 data: &mut self.error,251 vtable: self.vtable,3 unmodified lines255 }256 257 /// Iterator of errors in an `Exception`.258 pub struct Errors<'a> {259- next: Option<&'a (dyn Error + 'static)>,259+ next: Option<&'a (dyn StdError + 'static)>,260 }261 262 impl<'a> Iterator for Errors<'a> {263- type Item = &'a (dyn Error + 'static);263+ type Item = &'a (dyn StdError + 'static);264 265 fn next(&mut self) -> Option<Self::Item> {266 let next = self.next.take()?;267 self.next = next.source();25 unmodified lines293 use std::sync::*;294 295 #[derive(Debug)]296 struct HasDrop(Box<Arc<Mutex<bool>>>);297- impl Error for HasDrop {}297+ impl StdError for HasDrop {}298 impl Display for HasDrop {299 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {300 write!(f, "does something")301 }16 unmodified lines