Skip to content

Commit 64c6837

Browse files
authored
Merge pull request #148 from dtolnay/unit
Resolve let_unit_value pedantic lint in generated code
2 parents 9e4dcdb + 2e7587c commit 64c6837

File tree

2 files changed

+36
-14
lines changed

2 files changed

+36
-14
lines changed

src/expand.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ pub fn expand(input: &mut Item, is_local: bool) {
112112
fn lint_suppress_with_body() -> Attribute {
113113
parse_quote! {
114114
#[allow(
115+
clippy::let_unit_value,
115116
clippy::type_complexity,
116117
clippy::type_repetition_in_bounds,
117118
clippy::used_underscore_binding
@@ -344,23 +345,19 @@ fn transform_block(sig: &mut Signature, block: &mut Block) {
344345
}
345346

346347
let stmts = &block.stmts;
347-
let ret_ty = match &sig.output {
348-
ReturnType::Default => quote_spanned!(block.brace_token.span=> ()),
349-
ReturnType::Type(_, ret) => quote!(#ret),
350-
};
351-
352-
let box_pin = quote_spanned!(block.brace_token.span=>
353-
Box::pin(async move {
354-
let __ret: #ret_ty = {
355-
#(#decls)*
356-
#(#stmts)*
357-
};
358-
348+
let let_ret = match &sig.output {
349+
ReturnType::Default => quote_spanned! {block.brace_token.span=>
350+
let _: () = { #(#decls)* #(#stmts)* };
351+
},
352+
ReturnType::Type(_, ret) => quote_spanned! {block.brace_token.span=>
353+
let __ret: #ret = { #(#decls)* #(#stmts)* };
359354
#[allow(unreachable_code)]
360355
__ret
361-
})
356+
},
357+
};
358+
let box_pin = quote_spanned!(block.brace_token.span=>
359+
Box::pin(async move { #let_ret })
362360
);
363-
364361
block.stmts = parse_quote!(#box_pin);
365362
}
366363

tests/test.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,3 +1233,28 @@ pub mod issue145 {
12331233
async fn connect(&self) -> Result<Self::Connection, Self::Error>;
12341234
}
12351235
}
1236+
1237+
// https://github.com/dtolnay/async-trait/issues/147
1238+
pub mod issue147 {
1239+
#![deny(clippy::let_unit_value)]
1240+
1241+
use async_trait::async_trait;
1242+
1243+
pub struct MyType;
1244+
1245+
#[async_trait]
1246+
pub trait MyTrait {
1247+
async fn x();
1248+
async fn y() -> ();
1249+
async fn z();
1250+
}
1251+
1252+
#[async_trait]
1253+
impl MyTrait for MyType {
1254+
async fn x() {}
1255+
async fn y() -> () {}
1256+
async fn z() {
1257+
unimplemented!()
1258+
}
1259+
}
1260+
}

0 commit comments

Comments
 (0)