rust-lang / rust-lang/rust-clippy
`needless_pass_by_value` lint does not trigger on `async fn`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
The needless_pass_by_value lint does not fire for async fn, which makes it ineffective in projects that use async functions extensively. I am not sure whether this behavior is intended though.
Lint Name
needless_pass_by_value
Reproducer
I tried this code:
#![forbid(clippy::needless_pass_by_value)]
use std::hint::black_box;
fn main() {
black_box(take_value_1);
black_box(take_value_2);
}
struct Foo;
async fn take_value_1(x: Foo) {
black_box(&x);
}
fn take_value_2(x: Foo) {
black_box(&x);
}
I expected clippy to emit an error for both take_value_1 and take_value_2, since neither function consumes its Foo argument.
However, only take_value_2 triggers the lint. take_value_1 does not:
error: this argument is passed by value, but not consumed in the function body
--> src\main.rs:16:20
|
16 | fn take_value_2(x: Foo) {
| ^^^
|
help: or consider marking this type as `Copy`
--> src\main.rs:10:1
|
10 | struct Foo;
| ^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_value
note: the lint level is defined here
--> src\main.rs:1:11
|
1 | #![forbid(clippy::needless_pass_by_value)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: consider taking a reference instead
|
16 | fn take_value_2(x: &Foo) {
| +
error: could not compile `tt` (bin "tt") due to 1 previous error
Version
rustc 1.87.0 (17067e9ac 2025-05-09)
binary: rustc
commit-hash: 17067e9ac6d7ecb70e50f92c1944e545188d2359
commit-date: 2025-05-09
host: x86_64-pc-windows-gnu
release: 1.87.0
LLVM version: 20.1.1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Use the needless_pass_by_value lint and the supplied Rust reproducer as the entry point; compare diagnostics for take_value_1 and take_value_2. Done means the lint reports the async function as well as the synchronous function.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100