Skip to content

Commit

Permalink
Merge pull request #148 from dtolnay/unit
Browse files Browse the repository at this point in the history
Resolve let_unit_value pedantic lint in generated code
  • Loading branch information
dtolnay committed Mar 5, 2021
2 parents 9e4dcdb + 2e7587c commit 64c6837
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ pub fn expand(input: &mut Item, is_local: bool) {
fn lint_suppress_with_body() -> Attribute {
parse_quote! {
#[allow(
clippy::let_unit_value,
clippy::type_complexity,
clippy::type_repetition_in_bounds,
clippy::used_underscore_binding
Expand Down Expand Up @@ -344,23 +345,19 @@ fn transform_block(sig: &mut Signature, block: &mut Block) {
}

let stmts = &block.stmts;
let ret_ty = match &sig.output {
ReturnType::Default => quote_spanned!(block.brace_token.span=> ()),
ReturnType::Type(_, ret) => quote!(#ret),
};

let box_pin = quote_spanned!(block.brace_token.span=>
Box::pin(async move {
let __ret: #ret_ty = {
#(#decls)*
#(#stmts)*
};

let let_ret = match &sig.output {
ReturnType::Default => quote_spanned! {block.brace_token.span=>
let _: () = { #(#decls)* #(#stmts)* };
},
ReturnType::Type(_, ret) => quote_spanned! {block.brace_token.span=>
let __ret: #ret = { #(#decls)* #(#stmts)* };
#[allow(unreachable_code)]
__ret
})
},
};
let box_pin = quote_spanned!(block.brace_token.span=>
Box::pin(async move { #let_ret })
);

block.stmts = parse_quote!(#box_pin);
}

Expand Down
25 changes: 25 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1233,3 +1233,28 @@ pub mod issue145 {
async fn connect(&self) -> Result<Self::Connection, Self::Error>;
}
}

// https://github.com/dtolnay/async-trait/issues/147
pub mod issue147 {
#![deny(clippy::let_unit_value)]

use async_trait::async_trait;

pub struct MyType;

#[async_trait]
pub trait MyTrait {
async fn x();
async fn y() -> ();
async fn z();
}

#[async_trait]
impl MyTrait for MyType {
async fn x() {}
async fn y() -> () {}
async fn z() {
unimplemented!()
}
}
}

0 comments on commit 64c6837

Please sign in to comment.