Skip to content

Commit b1d8e1a

Browse files
authored
Merge pull request dtolnay#155 from dtolnay/items
Avoid items_after_statements lint in generated code
2 parents 926aeb5 + a7a4796 commit b1d8e1a

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

src/expand.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,17 +359,23 @@ fn transform_block(context: Context, sig: &mut Signature, block: &mut Block) {
359359
let stmts = &block.stmts;
360360
let let_ret = match &mut sig.output {
361361
ReturnType::Default => quote_spanned! {block.brace_token.span=>
362-
let _: () = { #(#decls)* #(#stmts)* };
362+
#(#decls)*
363+
let _: () = { #(#stmts)* };
363364
},
364365
ReturnType::Type(_, ret) => {
365366
if contains_associated_type_impl_trait(context, ret) {
366-
quote!(#(#decls)* #(#stmts)*)
367+
if decls.is_empty() {
368+
quote!(#(#stmts)*)
369+
} else {
370+
quote!(#(#decls)* { #(#stmts)* })
371+
}
367372
} else {
368373
quote_spanned! {block.brace_token.span=>
369374
if let ::core::option::Option::Some(__ret) = ::core::option::Option::None::<#ret> {
370375
return __ret;
371376
}
372-
let __ret: #ret = { #(#decls)* #(#stmts)* };
377+
#(#decls)*
378+
let __ret: #ret = { #(#stmts)* };
373379
#[allow(unreachable_code)]
374380
__ret
375381
}

tests/test.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,3 +1300,25 @@ pub mod issue152 {
13001300
async fn f(&self) -> Self::Assoc {}
13011301
}
13021302
}
1303+
1304+
// https://github.com/dtolnay/async-trait/issues/154
1305+
pub mod issue154 {
1306+
#![deny(clippy::items_after_statements)]
1307+
1308+
use async_trait::async_trait;
1309+
1310+
#[async_trait]
1311+
pub trait MyTrait {
1312+
async fn f(&self);
1313+
}
1314+
1315+
pub struct Struct;
1316+
1317+
#[async_trait]
1318+
impl MyTrait for Struct {
1319+
async fn f(&self) {
1320+
const MAX: u16 = 128;
1321+
println!("{}", MAX);
1322+
}
1323+
}
1324+
}

0 commit comments

Comments
 (0)