Skip to content
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

FP with needless_pass_by_ref_mut, async function and closures #11610

Closed
WaffleLapkin opened this issue Oct 4, 2023 · 3 comments · Fixed by #11622
Closed

FP with needless_pass_by_ref_mut, async function and closures #11610

WaffleLapkin opened this issue Oct 4, 2023 · 3 comments · Fixed by #11622
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

@WaffleLapkin
Copy link
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

@WaffleLapkin WaffleLapkin 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 Oct 4, 2023
@GuillaumeGomez
Copy link
Member

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

@WaffleLapkin
Copy link
Member Author

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

@GuillaumeGomez
Copy link
Member

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

@bors bors closed this as completed in 2640d5c Oct 17, 2023
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
2 participants