diff options
author | Dmitry <[email protected]> | 2020-08-09 14:35:51 +0100 |
---|---|---|
committer | Dmitry <[email protected]> | 2020-08-09 14:39:32 +0100 |
commit | 8068302fefc75440b823f4bf1731a5f347d7c767 (patch) | |
tree | 251b967182e79bc82a58c2fb208c688f6152df1f /crates/ra_assists/src/handlers/fill_match_arms.rs | |
parent | 1a43a0f63e0008787225abb6fb2baef97b6a39e0 (diff) | |
parent | 8a57afe5a4bfab40072a83f7dc4ca560bf860919 (diff) |
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'crates/ra_assists/src/handlers/fill_match_arms.rs')
-rw-r--r-- | crates/ra_assists/src/handlers/fill_match_arms.rs | 29 |
1 files changed, 13 insertions, 16 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..6698d1a27 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 { |
@@ -199,12 +197,11 @@ fn build_pat(db: &RootDatabase, module: hir::Module, var: hir::EnumVariant) -> O | |||
199 | // FIXME: use HIR for this; it doesn't currently expose struct vs. tuple vs. unit variants though | 197 | // FIXME: use HIR for this; it doesn't currently expose struct vs. tuple vs. unit variants though |
200 | let pat: ast::Pat = match var.source(db).value.kind() { | 198 | let pat: ast::Pat = match var.source(db).value.kind() { |
201 | ast::StructKind::Tuple(field_list) => { | 199 | ast::StructKind::Tuple(field_list) => { |
202 | let pats = | 200 | let pats = iter::repeat(make::wildcard_pat().into()).take(field_list.fields().count()); |
203 | iter::repeat(make::placeholder_pat().into()).take(field_list.fields().count()); | ||
204 | make::tuple_struct_pat(path, pats).into() | 201 | make::tuple_struct_pat(path, pats).into() |
205 | } | 202 | } |
206 | ast::StructKind::Record(field_list) => { | 203 | ast::StructKind::Record(field_list) => { |
207 | let pats = field_list.fields().map(|f| make::bind_pat(f.name().unwrap()).into()); | 204 | let pats = field_list.fields().map(|f| make::ident_pat(f.name().unwrap()).into()); |
208 | make::record_pat(path, pats).into() | 205 | make::record_pat(path, pats).into() |
209 | } | 206 | } |
210 | ast::StructKind::Unit => make::path_pat(path), | 207 | ast::StructKind::Unit => make::path_pat(path), |