diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-07-31 19:12:38 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-07-31 19:12:38 +0100 |
commit | 38ab326aac70484cb951fe9389d788d525d41550 (patch) | |
tree | 0032223efeefca76340fb0a97f6f12d0e432a2a9 /crates/ra_assists/src/handlers/fill_match_arms.rs | |
parent | 5cade89d730b025082ff2df70aace259951a9ccf (diff) | |
parent | 98181087984157e27faba0b969e384f3c62c39d5 (diff) |
Merge #5631
5631: Finalize pattern grammar r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_assists/src/handlers/fill_match_arms.rs')
-rw-r--r-- | crates/ra_assists/src/handlers/fill_match_arms.rs | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/crates/ra_assists/src/handlers/fill_match_arms.rs b/crates/ra_assists/src/handlers/fill_match_arms.rs index 708e1bc6c..b2e14f9d7 100644 --- a/crates/ra_assists/src/handlers/fill_match_arms.rs +++ b/crates/ra_assists/src/handlers/fill_match_arms.rs | |||
@@ -43,7 +43,7 @@ pub(crate) fn fill_match_arms(acc: &mut Assists, ctx: &AssistContext) -> Option< | |||
43 | 43 | ||
44 | let mut arms: Vec<MatchArm> = match_arm_list.arms().collect(); | 44 | let mut arms: Vec<MatchArm> = match_arm_list.arms().collect(); |
45 | if arms.len() == 1 { | 45 | if arms.len() == 1 { |
46 | if let Some(Pat::PlaceholderPat(..)) = arms[0].pat() { | 46 | if let Some(Pat::WildcardPat(..)) = arms[0].pat() { |
47 | arms.clear(); | 47 | arms.clear(); |
48 | } | 48 | } |
49 | } | 49 | } |
@@ -116,17 +116,15 @@ pub(crate) fn fill_match_arms(acc: &mut Assists, ctx: &AssistContext) -> Option< | |||
116 | match (first_new_arm, ctx.config.snippet_cap) { | 116 | match (first_new_arm, ctx.config.snippet_cap) { |
117 | (Some(first_new_arm), Some(cap)) => { | 117 | (Some(first_new_arm), Some(cap)) => { |
118 | let extend_lifetime; | 118 | let extend_lifetime; |
119 | let cursor = match first_new_arm | 119 | let cursor = |
120 | .syntax() | 120 | match first_new_arm.syntax().descendants().find_map(ast::WildcardPat::cast) |
121 | .descendants() | 121 | { |
122 | .find_map(ast::PlaceholderPat::cast) | 122 | Some(it) => { |
123 | { | 123 | extend_lifetime = it.syntax().clone(); |
124 | Some(it) => { | 124 | Cursor::Replace(&extend_lifetime) |
125 | extend_lifetime = it.syntax().clone(); | 125 | } |
126 | Cursor::Replace(&extend_lifetime) | 126 | None => Cursor::Before(first_new_arm.syntax()), |
127 | } | 127 | }; |
128 | None => Cursor::Before(first_new_arm.syntax()), | ||
129 | }; | ||
130 | let snippet = render_snippet(cap, new_arm_list.syntax(), cursor); | 128 | let snippet = render_snippet(cap, new_arm_list.syntax(), cursor); |
131 | builder.replace_snippet(cap, old_range, snippet); | 129 | builder.replace_snippet(cap, old_range, snippet); |
132 | } | 130 | } |
@@ -152,7 +150,7 @@ fn does_pat_match_variant(pat: &Pat, var: &Pat) -> bool { | |||
152 | let first_node_text = |pat: &Pat| pat.syntax().first_child().map(|node| node.text()); | 150 | let first_node_text = |pat: &Pat| pat.syntax().first_child().map(|node| node.text()); |
153 | 151 | ||
154 | let pat_head = match pat { | 152 | let pat_head = match pat { |
155 | Pat::BindPat(bind_pat) => { | 153 | Pat::IdentPat(bind_pat) => { |
156 | if let Some(p) = bind_pat.pat() { | 154 | if let Some(p) = bind_pat.pat() { |
157 | first_node_text(&p) | 155 | first_node_text(&p) |
158 | } else { | 156 | } else { |