rust-lang / rust-lang/rust-clippy
New lint: Unnecessarily complex types
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
It would be nice to lint on return types that are more complex than necessary. Take for example the following function (playground):
fn unnecessary_result() -> Result<usize, ()> {
Ok(1)
}
The Result here is not necessary, because the function always returns an Ok variant.
I would also like to see a similar lint for fn f() -> Option<T> where f always returns Some.
Note this is not the same as https://rust-lang.github.io/rust-clippy/current/index.html#type_complexity, which is about return types that are hard to read, not return types that are unnecessary.
Possible output for the lint (just making this up here):
warning: unnecessary `Result` in return type
--> src/lib.rs:1:1
|
1 | fn unnecessary_result() -> Result<usize, ()> {
| ^^^^^^^^^^^^^^^^^ help: try removing the `Result` type: `usize`
2 | Ok(1)
| ^^^^^ note: only return value is an `Ok` variant
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 by comparing the proposed lint with Clippy's existing type_complexity lint and the issue's Result and Option examples. Done means detecting functions whose returns are always Ok or Some and producing a diagnostic that explains the unnecessary wrapper and suggested simpler type.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100