diff --git a/src/expand.rs b/src/expand.rs index 6cc6ef0..e78c6c4 100644 --- a/src/expand.rs +++ b/src/expand.rs @@ -359,17 +359,23 @@ fn transform_block(context: Context, sig: &mut Signature, block: &mut Block) { let stmts = &block.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 } diff --git a/tests/test.rs b/tests/test.rs index 6f74bee..604d092 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -1300,3 +1300,25 @@ pub mod issue152 { async fn f(&self) -> Self::Assoc {} } } + +// https://github.com/dtolnay/async-trait/issues/154 +pub mod issue154 { + #![deny(clippy::items_after_statements)] + + use async_trait::async_trait; + + #[async_trait] + pub trait MyTrait { + async fn f(&self); + } + + pub struct Struct; + + #[async_trait] + impl MyTrait for Struct { + async fn f(&self) { + const MAX: u16 = 128; + println!("{}", MAX); + } + } +}