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

needless_pass_by_ref_mut: false positive with closures #11620

Closed
Tracked by #79
emilk opened this issue Oct 6, 2023 · 1 comment · Fixed by #11621
Closed
Tracked by #79

needless_pass_by_ref_mut: false positive with closures #11620

emilk opened this issue Oct 6, 2023 · 1 comment · Fixed by #11621
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

@emilk
Copy link

emilk commented Oct 6, 2023

Summary

needless_pass_by_ref_mut gives a false positive when the mutable reference is captured by a closure

Lint Name

needless_pass_by_ref_mut

Reproducer

I tried this code:

fn set_true(b: &mut bool) {
    *b = true;
}

fn true_setter(b: &mut bool) -> impl FnOnce() + '_ {
    move || set_true(b)
}

I saw this happen:

warning: this argument is a mutable reference, but not used mutably
   --> crates/egui_demo_lib/src/demo/toggle_switch.rs:116:19
    |
116 | fn true_setter(b: &mut bool) -> impl FnOnce() + '_ {
    |                   ^^^^^^^^^ help: consider changing to: `&bool`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_ref_mut

I expected to see this happen: No warning

Version

rustc 1.73.0 (cc66ad468 2023-10-03)
binary: rustc
commit-hash: cc66ad468955717ab92600c770da8c1601a4ff33
commit-date: 2023-10-03
host: aarch64-apple-darwin
release: 1.73.0
LLVM version: 17.0.2

Additional Labels

No response

@emilk emilk 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 6, 2023
@GuillaumeGomez
Copy link
Member

Taking a look.

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
Development

Successfully merging a pull request may close this issue.

2 participants