Skip to content

Commit

Permalink
Refactor to highlight similarities and differences
Browse files Browse the repository at this point in the history
  • Loading branch information
shepmaster committed Mar 11, 2024
1 parent d9fd1bc commit 76cb8a4
Showing 1 changed file with 19 additions and 28 deletions.
47 changes: 19 additions & 28 deletions snafu-derive/src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,37 +51,28 @@ pub fn body(
quote! { -> ::core::result::Result<(), ::snafu::Report<#error_ty>> }
};

#[allow(clippy::collapsible_else_if)]
let block = if asyncness.is_some() {
if cfg!(feature = "rust_1_61") {
quote! {
{
let __snafu_body: #output_ty = async #block.await;
<::snafu::Report<_> as ::core::convert::From<_>>::from(__snafu_body)
}
}
} else {
quote! {
{
let __snafu_body: #output_ty = async #block.await;
::core::result::Result::map_err(__snafu_body, ::snafu::Report::from_error)
}
let captured_original_body = if asyncness.is_some() {
quote! { async #block.await }
} else {
quote! { (|| #block)() }
};

let ascribed_original_result = quote! {
let __snafu_body: #output_ty = #captured_original_body;
};

let block = if cfg!(feature = "rust_1_61") {
quote! {
{
#ascribed_original_result;
<::snafu::Report<_> as ::core::convert::From<_>>::from(__snafu_body)
}
}
} else {
if cfg!(feature = "rust_1_61") {
quote! {
{
let __snafu_body: #output_ty = (|| #block)();
<::snafu::Report<_> as ::core::convert::From<_>>::from(__snafu_body)
}
}
} else {
quote! {
{
let __snafu_body: #output_ty = (|| #block)();
::core::result::Result::map_err(__snafu_body, ::snafu::Report::from_error)
}
quote! {
{
#ascribed_original_result;
::core::result::Result::map_err(__snafu_body, ::snafu::Report::from_error)
}
}
};
Expand Down

0 comments on commit 76cb8a4

Please sign in to comment.