Skip to content

Commit

Permalink
Prepend early return to force unsize coercion
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Mar 7, 2021
1 parent 28ad5f9 commit c8b4dc5
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,10 @@ 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)* };
Expand All @@ -356,7 +360,12 @@ fn transform_block(sig: &mut Signature, block: &mut Block) {
},
};
let box_pin = quote_spanned!(block.brace_token.span=>
Box::pin(async move { #let_ret })
Box::pin(async move {
if let ::core::option::Option::Some(__ret) = ::core::option::Option::None::<#ret> {
return __ret;
}
#let_ret
})
);
block.stmts = parse_quote!(#box_pin);
}
Expand Down

0 comments on commit c8b4dc5

Please sign in to comment.