Skip to content

Commit

Permalink
Avoid items_after_statements lint in generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Mar 8, 2021
1 parent b3fdf43 commit 6167641
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,19 +357,24 @@ 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)* };
let _: () = { #(#decls)* #stmts };
},
ReturnType::Type(_, ret) => {
if contains_associated_type_impl_trait(context, ret) {
quote!(#(#decls)* #(#stmts)*)
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)* };
let __ret: #ret = { #(#decls)* #stmts };
#[allow(unreachable_code)]
__ret
}
Expand Down

0 comments on commit 6167641

Please sign in to comment.