rust-lang / rust-lang/rust-clippy

unnecessary_wraps: ignore functions that return type aliases?

Open
#6,517 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

type ThatsOk = Option<i32>;

fn new_ok() -> ThatsOk {
    Some(3)
}

fn main() {
    let _ = new_ok();
}
warning: this function's return value is unnecessarily wrapped by `Option`
 --> src/main.rs:3:1
  |
3 | / fn new_ok() -> ThatsOk {
4 | |     Some(3)
5 | | }
  | |_^
  |
  = note: `#[warn(clippy::unnecessary_wraps)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_wraps
help: remove `Option` from the return type...
  |
3 | fn new_ok() -> i32 {
  |                ^^^
help: ...and change the returning expressions
  |
4 |     3
  |

IMO the lint should not trigger here because we use a newtype type aliases here and making code work without them may take quite some effort which goes beyond removing a match or an .unwrap() in real world examples.

Thoughts?

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 reproducing the Rust example and tracing the unnecessary_wraps lint's handling of aliased return types. Done means the lint no longer warns for the shown type-alias case, with coverage for that behavior.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.