Open
Description
Lint idea:
let x = if [let]? _ {
{true,false}
} else {
{false,true}
}
// ... maybe some code not using x
if [!]?x {
do_something();
}
Can be rewritten as
match _ {
Some_::Thing(..) => do_something();
_ => {}
}
or
if _ {
do_something();
}
What to keep in mind when implementing this:
- Differ between
if
andif let
: Suggest rewriting it as oneif
in the first case and as amatch
in the second*. - Between the binding and the usage of the binding is no other use of the binding.
- Get the conditions right. -> Write many test cases with all combinations of conditions and returns.
- Maybe this lint should only trigger on
if/else
blocks returningtrue/false
, without doing anything else inside? - I couldn't come up with a lint name, so be creative :)
cc #4308
- Could conflict with the
single_match_else
lint, but this is a pedantic lint, so we can ignore this