Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve let_unit_value pedantic lint in generated code #148

Merged
merged 3 commits into from
Mar 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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!()
}
}
}