rust-lang / rust-lang/rust-clippy

More redundant_closure_for_method_calls

Open
#11,017 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-false-negative
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Summary

Here I suggest one more example for the redundant_closure_for_method_calls.

Lint Name

redundant_closure_for_method_calls

Reproducer

I tried this code:

#![feature(slice_group_by)]
#![warn(clippy::pedantic)]
fn main() {
    let data = [true, false, true, false, true, true, false, false, true];
    let _gs1 = data.group_by(|a, b| a == b);
}

I expected to see a lint firing like:

note: #[warn(clippy::redundant_closure_for_method_calls)] implied by #[warn(clippy::pedantic)]

Instead, this happened:

Nothing spotted by clippy. I expected Clippy to suggest me to use:

data.group_by(bool::eq);

Version
rustc 1.72.0-nightly (46514218f 2023-06-20)
binary: rustc
commit-hash: 46514218f6f31ad3a1510ecc32af47e9e486c27d
commit-date: 2023-06-20
host: x86_64-pc-windows-gnu
release: 1.72.0-nightly
LLVM version: 16.0.5

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the redundant_closure_for_method_calls lint and reproduce the Rust example using data.group_by(|a, b| a == b). Done means Clippy reports the lint, suggests data.group_by(bool::eq), and includes regression coverage for this case.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.