6

feature: Assist to turn match into matches! invocation by pocket7878 · Pull Requ...

 2 years ago
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.
neoserver,ios ssh client

Assist to turn match into matches! invocation by pocket7878 · Pull Request #13005 · rust-lang/rust-analyzer · GitHub

pocket7878

force-pushed the convert-two-arm-bool-match-to-matches-macro

branch from 8bdad1e to 6b83593 Compare

27 days ago

pocket7878

changed the title feature: Assist to turn match into matches! invocation

[WIP] feature: Assist to turn match into matches! invocation

27 days ago

pocket7878

marked this pull request as draft

27 days ago

pocket7878

force-pushed the convert-two-arm-bool-match-to-matches-macro

branch from 6b83593 to 5e54e62 Compare

27 days ago

pocket7878

changed the title [WIP] feature: Assist to turn match into matches! invocation

feature: Assist to turn match into matches! invocation

27 days ago

pocket7878

marked this pull request as ready for review

27 days ago

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.

pocket7878 reacted with thumbs up emoji All reactions

Contributor

Author

@pocket7878 pocket7878 18 days ago

Thank you for your review! Updated!

All reactions

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK