Description
What it does
I wonder if it makes sense to have a lint that checks for functions that wrap their return types in Option
or Result
unnecessarily i.e. functions that always return Ok()
or Some()
.
This could indicate there once was some refactoring which removed the Err()
or None
case and the function can be simplified to directly return the wrapped type instead of the Option/Result.
Categories (optional)
This could be complexity
or pedantic
lint.
What is the advantage of the recommended code over the original code
fn get_cool_number(a: bool, b: bool) -> Option<i32> {
if a && b {
return Some(42);
}
if a {
Some(0)
} else if b {
Some(1)
} else {
Some(1337)
}
}
could would be warned about and could be refactored to
fn get_cool_number(a: bool, b: bool) -> i32 {
if a && b {
return 42;
}
if a {
0
} else if b {
1
} else {
1337
}
}
Drawbacks
This would probably "push" option-wrapping into other functions which might be annoying, i.e.
let x = get_cool_number();
foo(x)
could become
let x = Some(get_cool_number());
foo(x)
if foo
requires an Option
The lint should not probably not apply to pub
fns as it suggests changing function signatures.