Skip to content

Commit

Permalink
Reduce nesting of items_after_statements workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Mar 8, 2021
1 parent 6167641 commit a7a4796
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,24 +357,25 @@ fn transform_block(context: Context, sig: &mut Signature, block: &mut Block) {
}

let stmts = &block.stmts;
let stmts = if decls.is_empty() {
quote!(#(#stmts)*)
} else {
quote!({ #(#stmts)* })
};
let let_ret = match &mut sig.output {
ReturnType::Default => quote_spanned! {block.brace_token.span=>
let _: () = { #(#decls)* #stmts };
#(#decls)*
let _: () = { #(#stmts)* };
},
ReturnType::Type(_, ret) => {
if contains_associated_type_impl_trait(context, ret) {
quote!(#(#decls)* #stmts)
if decls.is_empty() {
quote!(#(#stmts)*)
} else {
quote!(#(#decls)* { #(#stmts)* })
}
} else {
quote_spanned! {block.brace_token.span=>
if let ::core::option::Option::Some(__ret) = ::core::option::Option::None::<#ret> {
return __ret;
}
let __ret: #ret = { #(#decls)* #stmts };
#(#decls)*
let __ret: #ret = { #(#stmts)* };
#[allow(unreachable_code)]
__ret
}
Expand Down

0 comments on commit a7a4796

Please sign in to comment.