Skip to content

Commit e2742a0

Browse files
committed
Fix double_must_use for async functions
1 parent 7fe83ed commit e2742a0

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

clippy_lints/src/functions/must_use.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ use super::{DOUBLE_MUST_USE, MUST_USE_CANDIDATE, MUST_USE_UNIT};
2323
pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
2424
let attrs = cx.tcx.hir().attrs(item.hir_id());
2525
let attr = cx.tcx.get_attr(item.owner_id, sym::must_use);
26-
if let hir::ItemKind::Fn(ref sig, _generics, ref body_id) = item.kind {
26+
if let hir::ItemKind::Fn(ref sig, _generics, ref body_id) = item.kind && !sig.header.is_async() /* (#10486) */ {
27+
2728
let is_public = cx.effective_visibilities.is_exported(item.owner_id.def_id);
2829
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
2930
if let Some(attr) = attr {
@@ -43,7 +44,7 @@ pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>
4344
}
4445

4546
pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) {
46-
if let hir::ImplItemKind::Fn(ref sig, ref body_id) = item.kind {
47+
if let hir::ImplItemKind::Fn(ref sig, ref body_id) = item.kind && !sig.header.is_async() /* (#10486) */ {
4748
let is_public = cx.effective_visibilities.is_exported(item.owner_id.def_id);
4849
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
4950
let attrs = cx.tcx.hir().attrs(item.hir_id());
@@ -65,7 +66,7 @@ pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Imp
6566
}
6667

6768
pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) {
68-
if let hir::TraitItemKind::Fn(ref sig, ref eid) = item.kind {
69+
if let hir::TraitItemKind::Fn(ref sig, ref eid) = item.kind && !sig.header.is_async() /* (#10486) */ {
6970
let is_public = cx.effective_visibilities.is_exported(item.owner_id.def_id);
7071
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
7172

tests/ui/double_must_use.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ pub fn must_use_with_note() -> Result<(), ()> {
2121
unimplemented!();
2222
}
2323

24+
// vvvv Should not lint (#10486)
25+
#[must_use]
26+
async fn async_must_use() -> usize {
27+
unimplemented!();
28+
}
29+
2430
fn main() {
2531
must_use_result();
2632
must_use_tuple();

0 commit comments

Comments
 (0)