What it does
Replaces if let (Some(x), Ok(y)) = (x, y) by if let Some(x) = x && Ok(y) = y, i.e. when a tuple is constructed and then immediately matched against a destructuring pattern. Similarly for arrays.
Things like if let (Some(x), Some(y) = (y, x), albeit questionable, should not trigger the lint.
Advantage
- Separates independent checks
- Can short-circuit
Drawbacks
- Can short circuit
- With default formatting, can increase the number of lines
Example
if let (Some(x), Ok(y)) = (x, y) && let [Some(_), None] = [a, b] {
...
}
Could be written as:
if let Some(x) = x && let Ok(y) = y && let Some(_) = a && let None = b {
...
}
Comparison with existing lints
It seems likely that redundant_pattern_match can trigger as a follow-up.
Not a lint, but rust-analyzer's unwrap_tuple assist is the analog for assignments. Note that for assignments, (x, y) = (y, x); is entirely reasonable and idiomatic,
Additional Context
This pattern may have been used as a partial workaround before let chains were available.
What it does
Replaces
if let (Some(x), Ok(y)) = (x, y)byif let Some(x) = x && Ok(y) = y, i.e. when a tuple is constructed and then immediately matched against a destructuring pattern. Similarly for arrays.Things like
if let (Some(x), Some(y) = (y, x), albeit questionable, should not trigger the lint.Advantage
Drawbacks
Example
Could be written as:
Comparison with existing lints
It seems likely that
redundant_pattern_matchcan trigger as a follow-up.Not a lint, but rust-analyzer's
unwrap_tupleassist is the analog for assignments. Note that for assignments,(x, y) = (y, x);is entirely reasonable and idiomatic,Additional Context
This pattern may have been used as a partial workaround before let chains were available.