rust-lang / rust-lang/rust-clippy
`redundant_closure` false positive when interacting with `FnMut` closures
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
This is related to https://github.com/rust-lang/rust-clippy/issues/8073 but I believe it is sufficiently different:
Lint Name
redundant_closure
Reproducer
I tried this code:
#![allow(unused)]
fn minimal<L>(mut logic: L)
where
L: FnMut(()),
{
let _: Box<dyn FnMut()> = Box::new(move || {
Vec::new().into_iter().map(|d| logic(d));
});
}
I saw this happen:
> it compiled
Clippy suggests this closure is a false positive, but if you take its suggestion, it fails to compile:
cannot move out of `logic`, a captured variable in an `FnMut` closure
because you are moving logic into the box, instead of moving a closure that references logic into it
playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=7d085db100dcb0f863e3e6f72dd3523a
Version
rustc 1.57
Additional Labels
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the redundant_closure lint and reproduce the behavior using the Rust 1.57 example or its linked Playground. Compare Clippy's suggested rewrite with the original FnMut closure and confirm that the corrected behavior avoids the reported compile failure while retaining the lint's intended cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100