Skip to content

Commit

Permalink
Remove unneeded early return from unit case
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Mar 7, 2021
1 parent c8b4dc5 commit 3596fe7
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,27 +345,21 @@ fn transform_block(sig: &mut Signature, block: &mut Block) {
}

let stmts = &block.stmts;
let ret = match &sig.output {
ReturnType::Default => quote!(()),
ReturnType::Type(_, ret) => quote!(#ret),
};
let let_ret = match &sig.output {
ReturnType::Default => quote_spanned! {block.brace_token.span=>
let _: () = { #(#decls)* #(#stmts)* };
},
ReturnType::Type(_, ret) => 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)* };
#[allow(unreachable_code)]
__ret
},
};
let box_pin = quote_spanned!(block.brace_token.span=>
Box::pin(async move {
if let ::core::option::Option::Some(__ret) = ::core::option::Option::None::<#ret> {
return __ret;
}
#let_ret
})
Box::pin(async move { #let_ret })
);
block.stmts = parse_quote!(#box_pin);
}
Expand Down

0 comments on commit 3596fe7

Please sign in to comment.