Skip to content

needless_pass_by_value lint does not trigger on async fn #15136

Open
@skr2005

Description

@skr2005

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn't

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions