Skip to content

FP with needless_pass_by_ref_mut, async function and closures #11610

@WaffleLapkin

Description

@WaffleLapkin
Member

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

Activity

added
C-bugCategory: Clippy is not doing the correct thing
I-false-positiveIssue: The lint was triggered on code it shouldn't have
on Oct 4, 2023
GuillaumeGomez

GuillaumeGomez commented on Oct 6, 2023

@GuillaumeGomez
Member

It was already fixed. Sending a PR to add this test case.

added a commit that references this issue on Oct 6, 2023
WaffleLapkin

WaffleLapkin commented on Oct 6, 2023

@WaffleLapkin
MemberAuthor

@GuillaumeGomez when was it fixed? the latest nightly still produces the warning...

GuillaumeGomez

GuillaumeGomez commented on Oct 6, 2023

@GuillaumeGomez
Member

In #11492. Someone asked the same question as you in the PR and you have the answer in it. ;)

added a commit that references this issue on Oct 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

      Participants

      @GuillaumeGomez@WaffleLapkin

      Issue actions

        FP with `needless_pass_by_ref_mut`, async function and closures · Issue #11610 · rust-lang/rust-clippy