Skip to content

FP with needless_pass_by_ref_mut, async function and closures #11610

Closed
@WaffleLapkin

Description

@WaffleLapkin

Summary

needless_pass_by_ref_mut lint is wrongfully emitted in some weird cases involving async functions and closures.

Note that #11551 was supposed to fix a similar issue, however the latest nightly still wrongfully emits a lint in the example below.

I did not debug it, but the lint seems to be extremely flaky, for example at one point during the minimization removing an unused use resulted in a lint not being emitted, at another point removing unused field caused a similar effect, but then removing another unused field brought the lint back...

Lint Name

needless_pass_by_ref_mut

Reproducer

I tried this code:

async fn _f(v: &mut Vec<()>) {
    let x = || v.pop();
    _ = || || x;
}

(play)

I saw this happen:

warning: this argument is a mutable reference, but not used mutably
 --> src/lib.rs:1:16
  |
1 | async fn _f(v: &mut Vec<()>) {
  |                ^^^^^^^^^^^^ help: consider changing to: `&Vec<()>`
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_ref_mut
  = note: `#[warn(clippy::needless_pass_by_ref_mut)]` on by default

I expected to see this happen: no warning, v is used mutably via .pop().

Version

1.75.0-nightly (2023-10-03 187b8131d4f760f856b2)

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions