Fix collapsible_match false negative on if let chains (#16570) - #16624
Fix collapsible_match false negative on if let chains (#16570)#166240x-pankaj wants to merge 1 commit into
Conversation
|
r? @dswij rustbot has assigned @dswij. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
e7fd5f3 to
8c7ccf2
Compare
| @@ -0,0 +1,30 @@ | |||
| #![allow(clippy::collapsible_else_if, stable_features)] | |||
There was a problem hiding this comment.
Let's put the tests in this file together with the other collapsible_match tests in tests/ui/collapsible_match.rs
| }); | ||
| } | ||
| current = lhs; | ||
| } |
There was a problem hiding this comment.
Should probably factor the Let parsing out, seems to be duplicated here and in ::hir(..)
| /// Parses an `if let` expression, but returns an iterator of all let chains in the condition. | ||
| /// E.g., `if let Some(x) = y && let Some(z) = w` will return an iterator of both let | ||
| /// expressions. | ||
| pub fn hir_all(cx: &LateContext<'_>, expr: &Expr<'hir>) -> Option<Vec<Self>> { |
There was a problem hiding this comment.
returning Vec<Self> here doesn't seem right since the original struct was written without let-chains in mind.
Perhaps it's better if we just have a new struct LetChain instead.
|
☔ The latest upstream changes (possibly #16878) made this pull request unmergeable. Please resolve the merge conflicts. |
Fix
collapsible_matchfalse negative when the outer match is inside anif letchain.Previously,
collapsible_matchonly checked simpleif letexpressions. This PR adds support for let chains (e.g.,if true && let Some(x) = opt { match x { ... } }) by:IfLet::hir_all()to clippy_utils/src/higher.rs to parse all let bindings in an if conditionouter_guardto check_if_let so the binding isn't incorrectly collapsed when used elsewhere in the chainfixes #16570
@profetia
changelog: [
collapsible_match]: Fix false negative when match is inside anif letchain