Skip to content
Myr

Move Error::new backtrace capture to backtrace_if_absent macro

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Tolnay · committed by David Tolnay · parent ebd9101 · Browse files · 2 files+20 added−11 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+20 added−11 removed

  • other:+20 added−11 removed

2 files+20 added−11 removed

modified:src/backtrace.rs+17 added
15 unmodified lines
16 () => {17 None18 };19}2021#[cfg(backtrace)]22macro_rules! backtrace_if_absent {23 ($err:expr) => {24 match $err.backtrace() {25 Some(_) => None,26 None => Some(Backtrace::capture()),27 }28 };29}3031#[cfg(not(backtrace))]32macro_rules! backtrace_if_absent {33 ($err:expr) => {34 None35 };36}
modified:src/error.rs+3 added-11 removed
31 unmodified lines
32 pub fn new<E>(error: E) -> Self33 where34 E: StdError + Send + Sync + 'static,35 {36 // Captured here instead of in Error::construct to have one fewer layer37 // of wrapping visible in the backtrace.38 #[cfg(backtrace)]39 let backtrace = match error.backtrace() {40 Some(_) => None,41 None => Some(Backtrace::capture()),42 };4344 #[cfg(not(backtrace))]45 let backtrace = None;4636 let backtrace = backtrace_if_absent!(error);37 Error::construct(error, TypeId::of::<E>(), backtrace)38 }3940 pub(crate) fn new_adhoc<M>(message: M, backtrace: Option<Backtrace>) -> Self
2 unmodified lines
43 {44 Error::construct(MessageError(message), TypeId::of::<M>(), backtrace)45 }4647 // Takes backtrace as argument rather than capturing it here so that the48 // user sees one fewer layer of wrapping noise in the backtrace.49 fn construct<E>(error: E, type_id: TypeId, backtrace: Option<Backtrace>) -> Self50 where51 E: StdError + Send + Sync + 'static,52 {
451 unmodified lines