rust-lang / rust-lang/rust-clippy

unnecessary_wraps is too strict

Open
#6,427 7 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

The recently introduced unnecessary_wraps lint is quite strict, and sometimes the affected function cannot be refactored. An example is when the function is used for #[serde(default)]:

fn field_default() -> Option<i32> {
    Some(42)
}

#[derive(serde::Deserialize)]
struct S {
    #[serde(default = "field_default")]
    field: Option<i32>,
}

It is a bit unfortunate having to allow the clippy lint explicitly. I was wondering if you would consider to add a function naming pattern that ignores the lint, such as an _opt suffix or a try_ prefix.

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

Review the existing unnecessary_wraps lint and the #[serde(default)] example first. Decide whether an _opt suffix or try_ prefix should be supported, then run the relevant lint checks to verify that the chosen naming pattern handles this case without weakening other diagnostics.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.