Skip to content

needless_pass_by_ref_mut: false negative with fn and closures #12588

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

Open
klensy opened this issue Mar 29, 2024 · 0 comments
Open

needless_pass_by_ref_mut: false negative with fn and closures #12588

klensy opened this issue Mar 29, 2024 · 0 comments
Labels
C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't L-nursery Lint: Currently in the nursery group

Comments

@klensy
Copy link
Contributor

klensy commented Mar 29, 2024

Summary

No clippy warning for needless_pass_by_ref_mut when both wrapping fn and closure have mutable args.

Discovered while working on rust-lang/rust#123188

checked with clippy from playground 0.1.79 (2024-03-27 c9f8f34)
https://play.rust-lang.org/?version=nightly&mode=release&edition=2021&gist=047b73855da451dd617b8d43557b8d0d

Lint Name

needless_pass_by_ref_mut

Reproducer

I tried this code:

#![warn(clippy::needless_pass_by_ref_mut)]

fn main() {}

fn foo(n: &mut u8)->u8 {
    let x = |c: &mut u8| *c;
    x(n)
}

fn foo2(n: &mut u8)->u8 {
    let x = |c: &u8| *c;
    x(n)
}

fn foo3(n: &u8)->u8 {
    let x = |c: &u8| *c;
    x(n)
}

I expected to see this happen:
For foo should warn about unused &mut in fn args and closure. Probably should first warn about closure arg, because if closure fixed, it will successfully warn about fn args (as in foo2)

Instead, this happened:

No warn for foo

Version

No response

@klensy klensy added C-bug Category: Clippy is not doing the correct thing I-false-negative Issue: The lint should have been triggered on code, but wasn't labels Mar 29, 2024
@J-ZhengLi J-ZhengLi added the L-nursery Lint: Currently in the nursery group label Jul 9, 2024
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-negative Issue: The lint should have been triggered on code, but wasn't L-nursery Lint: Currently in the nursery group
Projects
None yet
Development

No branches or pull requests

2 participants