Skip to content

unused_async for an async fn in a trait #14704

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

Closed
onlycs opened this issue Apr 28, 2025 · 1 comment · Fixed by #14720
Closed

unused_async for an async fn in a trait #14704

onlycs opened this issue Apr 28, 2025 · 1 comment · Fixed by #14720
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@onlycs
Copy link

onlycs commented Apr 28, 2025

Summary

If you have an async function in a trait that does nothing by default:

trait MyTrait {
  // having a body here makes its implementation optional
  async fn completed(self, ...) {}
}

sure, the async isn't used, but you want implementers to be able to use await in an overridden implementation. In this case, unused_async should not be warned

Lint Name

unused_async

Reproducer

I tried this code:

pub trait Action {
    // ...

    async fn cancel(self: Arc<Self>) {}
}

I saw this happen:

clippy: unused `async` for function with no await statements
consider removing the `async` from this function

I expected to see this happen:
No warning

Version

rustc 1.88.0-nightly (0b45675cf 2025-03-31)
binary: rustc
commit-hash: 0b45675cfcec57f30a3794e1a1e18423aa9cf200
commit-date: 2025-03-31
host: x86_64-unknown-linux-gnu
release: 1.88.0-nightly
LLVM version: 20.1.1

Additional Labels

  • I-suggestion-causes-warning
@onlycs onlycs added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Apr 28, 2025
@profetia
Copy link
Contributor

@rustbot claim

github-merge-queue bot pushed a commit that referenced this issue May 5, 2025
Closes #14704

changelog: [`unused_async`] fix FP on default impl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants