feature: Assist to turn match into matches! invocation by pocket7878 · Pull Requ...
source link: https://github.com/rust-lang/rust-analyzer/pull/13005
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Assist to turn match into matches! invocation by pocket7878 · Pull Request #13005 · rust-lang/rust-analyzer · GitHub
force-pushed the convert-two-arm-bool-match-to-matches-macro
changed the title
feature: Assist to turn match into matches! invocation
[WIP] feature: Assist to turn match into matches! invocation
force-pushed the convert-two-arm-bool-match-to-matches-macro
changed the title
[WIP] feature: Assist to turn match into matches! invocation
feature: Assist to turn match into matches! invocation
for arm in match_arm_list.arms() { |
||
if matches!(arm.pat(), Some(Pat::WildcardPat(_))) && arm.guard().is_none() { |
||
wildcard_expr = arm.expr(); |
||
} else if !matches!(arm.pat(), Some(Pat::WildcardPat(_))) { |
||
normal_arm = Some(arm.clone()); |
||
normal_expr = arm.expr(); |
||
} |
||
} |
This is rather limiting, ideally we want this assist to also work in scenarious like
match option {
Some(_) => true,
None => (),
}
Since we only ever expect two patterns here (we could support more but that makes things rather difficult so we shouldn't for the time being until r-a gets a better understanding of patterns) we should just always pick the pattern of the first arm unconditionally. Given arms are tried in top to bottom order we will always pick the correct pattern (+ guard) that way. Then we only need to check if the the body is true or not and adjust accordingly.
That makes this code here even simple, we don't need to bother looking at the second arm at all.
I'll review the rest after this has been addressed, since that will change a lot of things. If there are questions regarding this feel free to ask.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK