rust-lang / rust-lang/rust-clippy

clippy::redundant_closure suggestion unnecessarily complicated

Open
#3,974 4 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-enhancement L-suggestion
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Clippy rightfully suggests to simplify a map with a as_str () in the closure to us as_str directly. However the given suggestion is a bit too complicated and verbose given that the String module is always imported:

warning: redundant closure found
   --> src/main.rs:317:30
    |
317 |         version.as_ref().map(|v| v.as_str()),
    |                              ^^^^^^^^^^^^^^ help: remove closure as shown: `std::string::String::as_str`
    |
    = note: #[warn(clippy::redundant_closure)] on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure

It would be gread if the lint would say:

^^^^^^^^^^^^^^ help:  remove closure as shown: `String::as_str`

instead.

The version is:

clippy 0.0.212 (1fac3808 2019-02-20)

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 by locating the redundant_closure lint implementation and its suggestion-generation entry point. Reproduce the reported map(|v| v.as_str()) case, then add or update coverage so the help text uses String::as_str rather than std::string::String::as_str.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.