Skip to content
Myr

error.rs

This file

Path

src/error.rs

426 lines · 11.5 KiB · Rust

Last changed by

Add Error::root_cause accessorDavid Tolnaybefore adoption1ea72bb

History of this file

Take it

Add context method to ErrorDavid Tolnaybefore adoption41fde4c

line 1why, one step back
1use crate::context::ContextError;

Rename exception module to errorDavid Tolnaybefore adoption2000930

line 2why, one step back
2use std::any::TypeId;

Import std::error::Error as StdErrorDavid Tolnaybefore adoption7afc190

line 3why, one step back
3use std::error::Error as StdError;

Rename exception module to errorDavid Tolnaybefore adoption2000930

lines 4–8why, one step back
4use std::fmt::{self, Debug, Display};
5use std::mem;6use std::ops::{Deref, DerefMut};7use std::ptr;8

Detect nightly and only expose backtrace if availableDavid Tolnaybefore adoption270ea5e

lines 9–11why, one step back
9#[cfg(backtrace)]
10use std::backtrace::{Backtrace, BacktraceStatus};11

Rename Exception to ErrorDavid Tolnaybefore adoption5535ffc

line 12why, one step back
12/// The `Error` type, a wrapper around a dynamic error type.

Rename exception module to errorDavid Tolnaybefore adoption2000930

line 13why, one step back
13///

Touch up documentation on Error structDavid Tolnaybefore adoptiona8ce6e4

line 14why, one step back
14/// `Error` works a lot like `Box<dyn std::error::Error>`, but with these

Wrap comments to 80 columnsDavid Tolnaybefore adoption9745066

line 15why, one step back
15/// differences:

Rename exception module to errorDavid Tolnaybefore adoption2000930

line 16why, one step back
16///

Touch up documentation on Error structDavid Tolnaybefore adoptiona8ce6e4

lines 17–21why, one step back
17/// - `Error` requires that the error is `Send`, `Sync`, and `'static`.
18/// - `Error` guarantees that a backtrace is available, even if the underlying19/// error type does not provide one.20/// - `Error` is represented as a narrow pointer &mdash; exactly one word in21/// size instead of two.

Rename Exception to ErrorDavid Tolnaybefore adoption5535ffc

line 22why, one step back
22pub struct Error {

Rename InnerException to ErrorImplDavid Tolnaybefore adoption68dcc84

line 23why, one step back
23 inner: Box<ErrorImpl<()>>,

Rename exception module to errorDavid Tolnaybefore adoption2000930

lines 24–25why, one step back
24}
25

Rename Exception to ErrorDavid Tolnaybefore adoption5535ffc

line 26why, one step back
26impl Error {

Change all remaining exception related wordingDavid Tolnaybefore adoption94d944c

line 27why, one step back
27 /// Create a new error object from any error type.

Rename exception module to errorDavid Tolnaybefore adoption2000930

line 28why, one step back
28 ///

Wrap comments to 80 columnsDavid Tolnaybefore adoption9745066

lines 29–30why, one step back
29 /// The error type must be threadsafe and `'static`, so that the `Error`
30 /// will be as well.

Rename exception module to errorDavid Tolnaybefore adoption2000930

line 31why, one step back
31 ///

Wrap comments to 80 columnsDavid Tolnaybefore adoption9745066

lines 32–33why, one step back
32 /// If the error type does not provide a backtrace, a backtrace will be
33 /// created here to ensure that a backtrace exists.

Use Self in signatures of Error constructorsDavid Tolnaybefore adoption1ee4337

line 34why, one step back
34 pub fn new<E>(error: E) -> Self

Rename exception module to errorDavid Tolnaybefore adoption2000930

line 35why, one step back
35 where

Import std::error::Error as StdErrorDavid Tolnaybefore adoption7afc190

line 36why, one step back
36 E: StdError + Send + Sync + 'static,

Rename exception module to errorDavid Tolnaybefore adoption2000930

line 37why, one step back
37 {

Remove a layer of wrapping from debug mode backtracesDavid Tolnaybefore adoption97314ac

lines 38–45why, one step back
38 // Captured here instead of in Error::construct to have one fewer layer
39 // of wrapping visible in the backtrace.40 #[cfg(backtrace)]41 let backtrace = match error.backtrace() {42 Some(_) => None,43 None => Some(Backtrace::capture()),44 };45

Remove use of attributes on function parametersDavid Tolnaybefore adoptiona2d7e2f

lines 46–49why, one step back
46 #[cfg(not(backtrace))]
47 let backtrace = None;4849 Error::construct(error, TypeId::of::<E>(), backtrace)

Rename exception module to errorDavid Tolnaybefore adoption2000930

lines 50–51why, one step back
50 }
51

Remove use of attributes on function parametersDavid Tolnaybefore adoptiona2d7e2f

line 52why, one step back
52 pub(crate) fn new_adhoc<M>(message: M, backtrace: Option<Backtrace>) -> Self

Rename exception module to errorDavid Tolnaybefore adoption2000930

lines 53–55why, one step back
53 where
54 M: Display + Debug + Send + Sync + 'static,55 {

Remove use of attributes on function parametersDavid Tolnaybefore adoptiona2d7e2f

line 56why, one step back
56 Error::construct(MessageError(message), TypeId::of::<M>(), backtrace)

Rename exception module to errorDavid Tolnaybefore adoption2000930

lines 57–58why, one step back
57 }
58

Remove use of attributes on function parametersDavid Tolnaybefore adoptiona2d7e2f

line 59why, one step back
59 fn construct<E>(error: E, type_id: TypeId, backtrace: Option<Backtrace>) -> Self

Rename exception module to errorDavid Tolnaybefore adoption2000930

line 60why, one step back
60 where

Import std::error::Error as StdErrorDavid Tolnaybefore adoption7afc190

line 61why, one step back
61 E: StdError + Send + Sync + 'static,

Rename exception module to errorDavid Tolnaybefore adoption2000930

lines 62–63why, one step back
62 {
63 unsafe {

Specify generic params on every transmuteDavid Tolnaybefore adoption46ad742

lines 64–65why, one step back
64 let obj = mem::transmute::<&dyn StdError, TraitObject>(&error);
65 let inner = Box::new(ErrorImpl {

Remove a layer of wrapping from debug mode backtracesDavid Tolnaybefore adoption97314ac

line 66why, one step back
66 vtable: obj.vtable,

Rename exception module to errorDavid Tolnaybefore adoption2000930

lines 67–69why, one step back
67 type_id,
68 backtrace,69 error,

Specify generic params on every transmuteDavid Tolnaybefore adoption46ad742

line 70why, one step back
70 });

Rename Exception to ErrorDavid Tolnaybefore adoption5535ffc

line 71why, one step back
71 Error {

Specify generic params on every transmuteDavid Tolnaybefore adoption46ad742

line 72why, one step back
72 inner: mem::transmute::<Box<ErrorImpl<E>>, Box<ErrorImpl<()>>>(inner),

Rename exception module to errorDavid Tolnaybefore adoption2000930

lines 73–74why, one step back
73 }
74 }

Add context method to ErrorDavid Tolnaybefore adoption41fde4c

lines 75–77why, one step back
75 }
7677 /// Wrap the error value with additional context.

Link to Context trait from Error::context methodDavid Tolnaybefore adoption61e587f

lines 78–81why, one step back
78 ///
79 /// For attaching context to a `Result` as it is propagated, the80 /// [`Context`][crate::Context] extension trait may be more convenient than81 /// this function.

Add context method to ErrorDavid Tolnaybefore adoption41fde4c

lines 82–89why, one step back
82 pub fn context<C>(self, context: C) -> Self
83 where84 C: Display + Send + Sync + 'static,85 {86 Error::from(ContextError {87 error: self,88 context,89 })

Rename exception module to errorDavid Tolnaybefore adoption2000930

lines 90–91why, one step back
90 }
91

Rename Exception to ErrorDavid Tolnaybefore adoption5535ffc

line 92why, one step back
92 /// Get the backtrace for this Error.

Detect nightly and only expose backtrace if availableDavid Tolnaybefore adoption270ea5e

lines 93–96why, one step back
93 ///
94 /// Backtraces are only available on the nightly channel. Tracking issue:95 /// [rust-lang/rust#53487][tracking].96 ///

Mention env var in Error::backtrace documentationDavid Tolnaybefore adoption4119806

lines 97–101why, one step back
97 /// In order for the backtrace to be meaningful, the environment variable
98 /// `RUST_LIB_BACKTRACE=1` must be defined. Backtraces are somewhat99 /// expensive to capture in Rust, so we don't necessarily want to be100 /// capturing them all over the place all the time.101 ///

Detect nightly and only expose backtrace if availableDavid Tolnaybefore adoption270ea5e

lines 102–103why, one step back
102 /// [tracking]: https://github.com/rust-lang/rust/issues/53487
103 #[cfg(backtrace)]

Rename exception module to errorDavid Tolnaybefore adoption2000930

line 104why, one step back
104 pub fn backtrace(&self) -> &Backtrace {

Wrap comments to 80 columnsDavid Tolnaybefore adoption9745066

lines 105–107why, one step back
105 // NB: this unwrap can only fail if the underlying error's backtrace
106 // method is nondeterministic, which would only happen in maliciously107 // constructed code

Rename exception module to errorDavid Tolnaybefore adoption2000930

lines 108–111why, one step back
108 self.inner
109 .backtrace110 .as_ref()111 .or_else(|| self.inner.error().backtrace())

Change all remaining exception related wordingDavid Tolnaybefore adoption94d944c

line 112why, one step back
112 .expect("backtrace capture failed")

Rename exception module to errorDavid Tolnaybefore adoption2000930

lines 113–114why, one step back
113 }
114

Rename Errors to ChainDavid Tolnaybefore adoptionf972193

line 115why, one step back
115 /// An iterator of the chain of source errors contained by this Error.

Rename exception module to errorDavid Tolnaybefore adoption2000930

line 116why, one step back
116 ///

Rename Errors to ChainDavid Tolnaybefore adoptionf972193

line 117why, one step back
117 /// This iterator will visit every error in the cause chain of this error

Wrap comments to 80 columnsDavid Tolnaybefore adoption9745066

lines 118–119why, one step back
118 /// object, beginning with the error that this error object was created
119 /// from.

Rename Errors to ChainDavid Tolnaybefore adoptionf972193

lines 120–121why, one step back
120 pub fn chain(&self) -> Chain {
121 Chain {

Rename exception module to errorDavid Tolnaybefore adoption2000930

lines 122–125why, one step back
122 next: Some(self.inner.error()),
123 }124 }125

Add Error::root_cause accessorDavid Tolnaybefore adoption1ea72bb

lines 126–139why, one step back
126 /// The lowest level cause of this error &mdash; this error's cause's
127 /// cause's cause etc.128 ///129 /// The root cause is the last error in the iterator produced by130 /// [`chain()`][Error::chain].131 pub fn root_cause(&self) -> &(dyn StdError + 'static) {132 let mut chain = self.chain();133 let mut root_cause = chain.next().unwrap();134 for cause in chain {135 root_cause = cause;136 }137 root_cause138 }139

Change all remaining exception related wordingDavid Tolnaybefore adoption94d944c

line 140why, one step back
140 /// Returns `true` if `E` is the type wrapped by this error object.

Move trait bounds to where-clausesDavid Tolnaybefore adoption7dcc851

lines 141–144why, one step back
141 pub fn is<E>(&self) -> bool
142 where143 E: Display + Debug + Send + Sync + 'static,144 {

Rename exception module to errorDavid Tolnaybefore adoption2000930

lines 145–147why, one step back
145 TypeId::of::<E>() == self.inner.type_id
146 }147

Change all remaining exception related wordingDavid Tolnaybefore adoption94d944c

line 148why, one step back
148 /// Attempt to downcast the error object to a concrete type.

Use Self in signatures of Error constructorsDavid Tolnaybefore adoption1ee4337

line 149why, one step back
149 pub fn downcast<E>(self) -> Result<E, Self>

Move trait bounds to where-clausesDavid Tolnaybefore adoption7dcc851

lines 150–152why, one step back
150 where
151 E: Display + Debug + Send + Sync + 'static,152 {

Rename exception module to errorDavid Tolnaybefore adoption2000930

lines 153–164why, one step back
153 if let Some(error) = self.downcast_ref::<E>() {
154 unsafe {155 let error = ptr::read(error);156 drop(ptr::read(&self.inner));157 mem::forget(self);158 Ok(error)159 }160 } else {161 Err(self)162 }163 }164

Change all remaining exception related wordingDavid Tolnaybefore adoption94d944c

line 165why, one step back
165 /// Downcast this error object by reference.

Add example to Error::downcast_refDavid Tolnaybefore adoption0c21b7a

lines 166–200why, one step back
166 ///
167 /// # Example168 ///169 /// ```170 /// # use anyhow::anyhow;171 /// # use std::fmt::{self, Display};172 /// # use std::task::Poll;173 /// #174 /// # #[derive(Debug)]175 /// # enum DataStoreError {176 /// # Censored(()),177 /// # }178 /// #179 /// # impl Display for DataStoreError {180 /// # fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {181 /// # unimplemented!()182 /// # }183 /// # }184 /// #185 /// # impl std::error::Error for DataStoreError {}186 /// #187 /// # const REDACTED_CONTENT: () = ();188 /// #189 /// # let error = anyhow!("...");190 /// # let root_cause = &error;191 /// #192 /// # let ret =193 /// // If the error was caused by redaction, then return a tombstone instead194 /// // of the content.195 /// match root_cause.downcast_ref::<DataStoreError>() {196 /// Some(DataStoreError::Censored(_)) => Ok(Poll::Ready(REDACTED_CONTENT)),197 /// None => Err(error),198 /// }199 /// # ;200 /// ```

Move trait bounds to where-clausesDavid Tolnaybefore adoption7dcc851

lines 201–204why, one step back
201 pub fn downcast_ref<E>(&self) -> Option<&E>
202 where203 E: Display + Debug + Send + Sync + 'static,204 {

Rename exception module to errorDavid Tolnaybefore adoption2000930

line 205why, one step back
205 if self.is::<E>() {

Import std::error::Error as StdErrorDavid Tolnaybefore adoption7afc190

line 206why, one step back
206 unsafe { Some(&*(self.inner.error() as *const dyn StdError as *const E)) }

Rename exception module to errorDavid Tolnaybefore adoption2000930

lines 207–211why, one step back
207 } else {
208 None209 }210 }211

Change all remaining exception related wordingDavid Tolnaybefore adoption94d944c

line 212why, one step back
212 /// Downcast this error object by mutable reference.

Move trait bounds to where-clausesDavid Tolnaybefore adoption7dcc851

lines 213–216why, one step back
213 pub fn downcast_mut<E>(&mut self) -> Option<&mut E>
214 where215 E: Display + Debug + Send + Sync + 'static,216 {

Rename exception module to errorDavid Tolnaybefore adoption2000930

line 217why, one step back
217 if self.is::<E>() {

Import std::error::Error as StdErrorDavid Tolnaybefore adoption7afc190

line 218why, one step back
218 unsafe { Some(&mut *(self.inner.error_mut() as *mut dyn StdError as *mut E)) }

Rename exception module to errorDavid Tolnaybefore adoption2000930

lines 219–223why, one step back
219 } else {
220 None221 }222 }223}

Remove use of attributes on function parametersDavid Tolnaybefore adoptiona2d7e2f

lines 224–226why, one step back
224
225#[cfg(not(backtrace))]226pub(crate) enum Backtrace {}

Rename exception module to errorDavid Tolnaybefore adoption2000930

line 227why, one step back
227

Move trait bounds to where-clausesDavid Tolnaybefore adoption7dcc851

lines 228–231why, one step back
228impl<E> From<E> for Error
229where230 E: StdError + Send + Sync + 'static,231{

Use Self in signatures of Error constructorsDavid Tolnaybefore adoption1ee4337

line 232why, one step back
232 fn from(error: E) -> Self {

Rename Exception to ErrorDavid Tolnaybefore adoption5535ffc

line 233why, one step back
233 Error::new(error)

Rename exception module to errorDavid Tolnaybefore adoption2000930

lines 234–236why, one step back
234 }
235}236

Rename Exception to ErrorDavid Tolnaybefore adoption5535ffc

line 237why, one step back
237impl Deref for Error {

Import std::error::Error as StdErrorDavid Tolnaybefore adoption7afc190

line 238why, one step back
238 type Target = dyn StdError + Send + Sync + 'static;

Remove as_dyn_error methods from ErrorDavid Tolnaybefore adoption73c7283

line 239why, one step back
239

Rename exception module to errorDavid Tolnaybefore adoption2000930

lines 240–244why, one step back
240 fn deref(&self) -> &Self::Target {
241 self.inner.error()242 }243}244

Rename Exception to ErrorDavid Tolnaybefore adoption5535ffc

line 245why, one step back
245impl DerefMut for Error {

Rename exception module to errorDavid Tolnaybefore adoption2000930

lines 246–250why, one step back
246 fn deref_mut(&mut self) -> &mut Self::Target {
247 self.inner.error_mut()248 }249}250

Rename Exception to ErrorDavid Tolnaybefore adoption5535ffc

line 251why, one step back
251impl Debug for Error {

Rename exception module to errorDavid Tolnaybefore adoption2000930

lines 252–254why, one step back
252 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
253 writeln!(f, "{}", self.inner.error())?;254

Touch up Debug impl for ErrorDavid Tolnaybefore adoption3cd7273

lines 255–256why, one step back
255 let mut chain = self.chain().skip(1).enumerate();
256 if let Some((n, error)) = chain.next() {

Rename exception module to errorDavid Tolnaybefore adoption2000930

lines 257–258why, one step back
257 writeln!(f, "\ncaused by:")?;
258 writeln!(f, "\t{}: {}", n, error)?;

Touch up Debug impl for ErrorDavid Tolnaybefore adoption3cd7273

line 259why, one step back
259 for (n, error) in chain {

Rename exception module to errorDavid Tolnaybefore adoption2000930

lines 260–263why, one step back
260 writeln!(f, "\t{}: {}", n, error)?;
261 }262 }263

Detect nightly and only expose backtrace if availableDavid Tolnaybefore adoption270ea5e

lines 264–277why, one step back
264 #[cfg(backtrace)]
265 {266 let backtrace = self.backtrace();267 match backtrace.status() {268 BacktraceStatus::Captured => {269 writeln!(f, "\n{}", backtrace)?;270 }271 BacktraceStatus::Disabled => {272 writeln!(273 f,274 "\nbacktrace disabled; run with RUST_LIB_BACKTRACE=1 environment variable to display a backtrace"275 )?;276 }277 _ => {}

Rename exception module to errorDavid Tolnaybefore adoption2000930

lines 278–284why, one step back
278 }
279 }280281 Ok(())282 }283}284

Rename Exception to ErrorDavid Tolnaybefore adoption5535ffc

line 285why, one step back
285impl Display for Error {

Rename exception module to errorDavid Tolnaybefore adoption2000930

lines 286–290why, one step back
286 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
287 write!(f, "{}", self.inner.error())288 }289}290

Rename Exception to ErrorDavid Tolnaybefore adoption5535ffc

lines 291–292why, one step back
291unsafe impl Send for Error {}
292unsafe impl Sync for Error {}

Rename exception module to errorDavid Tolnaybefore adoption2000930

line 293why, one step back
293

Rename Exception to ErrorDavid Tolnaybefore adoption5535ffc

line 294why, one step back
294impl Drop for Error {

Rename exception module to errorDavid Tolnaybefore adoption2000930

lines 295–301why, one step back
295 fn drop(&mut self) {
296 unsafe { ptr::drop_in_place(self.inner.error_mut()) }297 }298}299300// repr C to ensure that `E` remains in the final position301#[repr(C)]

Rename InnerException to ErrorImplDavid Tolnaybefore adoption68dcc84

line 302why, one step back
302struct ErrorImpl<E> {

Rename exception module to errorDavid Tolnaybefore adoption2000930

lines 303–316why, one step back
303 vtable: *const (),
304 type_id: TypeId,305 backtrace: Option<Backtrace>,306 error: E,307}308309// repr C to ensure that transmuting from trait objects is safe310#[repr(C)]311struct TraitObject {312 data: *const (),313 vtable: *const (),314}315316#[repr(transparent)]

Remove trait bounds from MessageError structDavid Tolnaybefore adoptioneac05d1

line 317why, one step back
317struct MessageError<M>(M);

Rename exception module to errorDavid Tolnaybefore adoption2000930

line 318why, one step back
318

Move trait bounds to where-clausesDavid Tolnaybefore adoption7dcc851

lines 319–322why, one step back
319impl<M> Debug for MessageError<M>
320where321 M: Display + Debug,322{

Rename exception module to errorDavid Tolnaybefore adoption2000930

lines 323–327why, one step back
323 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
324 Debug::fmt(&self.0, f)325 }326}327

Move trait bounds to where-clausesDavid Tolnaybefore adoption7dcc851

lines 328–331why, one step back
328impl<M> Display for MessageError<M>
329where330 M: Display + Debug,331{

Rename exception module to errorDavid Tolnaybefore adoption2000930

lines 332–336why, one step back
332 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
333 Display::fmt(&self.0, f)334 }335}336

Move trait bounds to where-clausesDavid Tolnaybefore adoption7dcc851

line 337why, one step back
337impl<M> StdError for MessageError<M> where M: Display + Debug + 'static {}

Rename exception module to errorDavid Tolnaybefore adoption2000930

line 338why, one step back
338

Rename InnerException to ErrorImplDavid Tolnaybefore adoption68dcc84

line 339why, one step back
339impl ErrorImpl<()> {

Import std::error::Error as StdErrorDavid Tolnaybefore adoption7afc190

line 340why, one step back
340 fn error(&self) -> &(dyn StdError + Send + Sync + 'static) {

Specify generic params on every transmuteDavid Tolnaybefore adoption46ad742

lines 341–346why, one step back
341 let object = TraitObject {
342 data: &self.error,343 vtable: self.vtable,344 };345346 unsafe { mem::transmute::<TraitObject, &(dyn StdError + Send + Sync + 'static)>(object) }

Rename exception module to errorDavid Tolnaybefore adoption2000930

lines 347–348why, one step back
347 }
348

Import std::error::Error as StdErrorDavid Tolnaybefore adoption7afc190

line 349why, one step back
349 fn error_mut(&mut self) -> &mut (dyn StdError + Send + Sync + 'static) {

Specify generic params on every transmuteDavid Tolnaybefore adoption46ad742

lines 350–354why, one step back
350 let object = TraitObject {
351 data: &mut self.error,352 vtable: self.vtable,353 };354

Rename exception module to errorDavid Tolnaybefore adoption2000930

line 355why, one step back
355 unsafe {

Specify generic params on every transmuteDavid Tolnaybefore adoption46ad742

line 356why, one step back
356 mem::transmute::<TraitObject, &mut (dyn StdError + Send + Sync + 'static)>(object)

Rename exception module to errorDavid Tolnaybefore adoption2000930

lines 357–360why, one step back
357 }
358 }359}360

Rename Errors to ChainDavid Tolnaybefore adoptionf972193

lines 361–362why, one step back
361/// Iterator of a chain of source errors.
362pub struct Chain<'a> {

Import std::error::Error as StdErrorDavid Tolnaybefore adoption7afc190

line 363why, one step back
363 next: Option<&'a (dyn StdError + 'static)>,

Rename exception module to errorDavid Tolnaybefore adoption2000930

lines 364–365why, one step back
364}
365

Rename Errors to ChainDavid Tolnaybefore adoptionf972193

line 366why, one step back
366impl<'a> Iterator for Chain<'a> {

Import std::error::Error as StdErrorDavid Tolnaybefore adoption7afc190

line 367why, one step back
367 type Item = &'a (dyn StdError + 'static);

Rename exception module to errorDavid Tolnaybefore adoption2000930

lines 368–380why, one step back
368
369 fn next(&mut self) -> Option<Self::Item> {370 let next = self.next.take()?;371 self.next = next.source();372 Some(next)373 }374}375376#[cfg(test)]377mod repr_correctness {378 use super::*;379 use std::marker::Unpin;380 use std::mem;

Replace Mutex<bool> with AtomicBoolDavid Tolnaybefore adoption794ba39

lines 381–383why, one step back
381 use std::sync::atomic::AtomicBool;
382 use std::sync::atomic::Ordering::SeqCst;383 use std::sync::Arc;

Rename exception module to errorDavid Tolnaybefore adoption2000930

lines 384–385why, one step back
384
385 #[test]

Change all remaining exception related wordingDavid Tolnaybefore adoption94d944c

line 386why, one step back
386 fn size_of_error() {

Rename Exception to ErrorDavid Tolnaybefore adoption5535ffc

line 387why, one step back
387 assert_eq!(mem::size_of::<Error>(), mem::size_of::<usize>());

Rename exception module to errorDavid Tolnaybefore adoption2000930

lines 388–389why, one step back
388 }
389

Simplify autotraits testDavid Tolnaybefore adoptionb0e25c5

lines 390–393why, one step back
390 #[test]
391 fn error_autotraits() {392 fn assert<E: Unpin + Send + Sync + 'static>() {}393 assert::<Error>();

Rename exception module to errorDavid Tolnaybefore adoption2000930

lines 394–396why, one step back
394 }
395396 #[test]

Improve naming in Drop testDavid Tolnaybefore adoption04931ad

line 397why, one step back
397 fn drop_works() {

Rename exception module to errorDavid Tolnaybefore adoption2000930

line 398why, one step back
398 #[derive(Debug)]

Improve naming in Drop testDavid Tolnaybefore adoption04931ad

lines 399–405why, one step back
399 struct DetectDrop {
400 has_dropped: Arc<AtomicBool>,401 }402403 impl StdError for DetectDrop {}404405 impl Display for DetectDrop {

Rename exception module to errorDavid Tolnaybefore adoption2000930

lines 406–409why, one step back
406 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
407 write!(f, "does something")408 }409 }

Improve naming in Drop testDavid Tolnaybefore adoption04931ad

lines 410–411why, one step back
410
411 impl Drop for DetectDrop {

Rename exception module to errorDavid Tolnaybefore adoption2000930

line 412why, one step back
412 fn drop(&mut self) {

Improve naming in Drop testDavid Tolnaybefore adoption04931ad

lines 413–414why, one step back
413 let already_dropped = self.has_dropped.swap(true, SeqCst);
414 assert!(!already_dropped);

Rename exception module to errorDavid Tolnaybefore adoption2000930

lines 415–417why, one step back
415 }
416 }417

Replace Mutex<bool> with AtomicBoolDavid Tolnaybefore adoption794ba39

line 418why, one step back
418 let has_dropped = Arc::new(AtomicBool::new(false));

Rename exception module to errorDavid Tolnaybefore adoption2000930

line 419why, one step back
419

Improve naming in Drop testDavid Tolnaybefore adoption04931ad

lines 420–422why, one step back
420 drop(Error::from(DetectDrop {
421 has_dropped: has_dropped.clone(),422 }));

Rename exception module to errorDavid Tolnaybefore adoption2000930

line 423why, one step back
423

Replace Mutex<bool> with AtomicBoolDavid Tolnaybefore adoption794ba39

line 424why, one step back
424 assert!(has_dropped.load(SeqCst));

Rename exception module to errorDavid Tolnaybefore adoption2000930

lines 425–426why, one step back
425 }
426}