Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalize backtrace capture to From<Backtrace> types, including Arc<Backtrace> #102

Merged
merged 2 commits into from Oct 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion impl/src/expand.rs
Expand Up @@ -367,7 +367,7 @@ fn from_initializer(from_field: &Field, backtrace_field: Option<&Field>) -> Toke
}
} else {
quote! {
#backtrace_member: std::backtrace::Backtrace::capture(),
#backtrace_member: std::convert::From::from(std::backtrace::Backtrace::capture()),
}
}
});
Expand Down
26 changes: 26 additions & 0 deletions tests/test_backtrace.rs
Expand Up @@ -59,6 +59,15 @@ pub mod structs {
backtrace: Option<Backtrace>,
}

#[derive(Error, Debug)]
#[error("...")]
pub struct ArcBacktraceFrom {
#[from]
source: Inner,
#[backtrace]
backtrace: Arc<Backtrace>,
}

#[test]
fn test_backtrace() {
let error = PlainBacktrace {
Expand Down Expand Up @@ -86,6 +95,9 @@ pub mod structs {

let error = OptBacktraceFrom::from(Inner);
assert!(error.backtrace().is_some());

let error = ArcBacktraceFrom::from(Inner);
assert!(error.backtrace().is_some());
}
}

Expand Down Expand Up @@ -152,6 +164,17 @@ pub mod enums {
},
}

#[derive(Error, Debug)]
pub enum ArcBacktraceFrom {
#[error("...")]
Test {
#[from]
source: Inner,
#[backtrace]
backtrace: Arc<Backtrace>,
},
}

#[test]
fn test_backtrace() {
let error = PlainBacktrace::Test {
Expand Down Expand Up @@ -179,6 +202,9 @@ pub mod enums {

let error = OptBacktraceFrom::from(Inner);
assert!(error.backtrace().is_some());

let error = ArcBacktraceFrom::from(Inner);
assert!(error.backtrace().is_some());
}
}

Expand Down