Open
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