Skip to content

Commit

Permalink
Merge pull request #155 from dtolnay/items
Browse files Browse the repository at this point in the history
Avoid items_after_statements lint in generated code
  • Loading branch information
dtolnay committed Mar 8, 2021
2 parents 926aeb5 + a7a4796 commit b1d8e1a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/expand.rs
Expand Up @@ -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
}
Expand Down
22 changes: 22 additions & 0 deletions tests/test.rs
Expand Up @@ -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);
}
}
}

0 comments on commit b1d8e1a

Please sign in to comment.