aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorToby Dimmick <[email protected]>2020-06-14 22:44:28 +0100
committerToby Dimmick <[email protected]>2020-06-14 22:44:51 +0100
commit41f5471f3e5dab3da345361a0924391d6267373f (patch)
treeb61c7af7c41949aa91d803408b97b09972e08001 /crates
parent34db4edb80ac614f5ca8d4e7bea4b6917368d6d6 (diff)
fill_match_arms bind pattern implementation
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_assists/src/handlers/fill_match_arms.rs16
1 files changed, 14 insertions, 2 deletions
diff --git a/crates/ra_assists/src/handlers/fill_match_arms.rs b/crates/ra_assists/src/handlers/fill_match_arms.rs
index 9905b9e9f..569efb768 100644
--- a/crates/ra_assists/src/handlers/fill_match_arms.rs
+++ b/crates/ra_assists/src/handlers/fill_match_arms.rs
@@ -136,8 +136,20 @@ fn is_variant_missing(existing_arms: &mut Vec<MatchArm>, var: &Pat) -> bool {
136} 136}
137 137
138fn does_pat_match_variant(pat: &Pat, var: &Pat) -> bool { 138fn does_pat_match_variant(pat: &Pat, var: &Pat) -> bool {
139 let pat_head = pat.syntax().first_child().map(|node| node.text()); 139 let first_node_text = |pat: &Pat| pat.syntax().first_child().map(|node| node.text());
140 let var_head = var.syntax().first_child().map(|node| node.text()); 140
141 let pat_head = match pat {
142 Pat::BindPat(bind_pat) => {
143 if let Some(p) = bind_pat.pat() {
144 first_node_text(&p)
145 } else {
146 return false;
147 }
148 }
149 pat => first_node_text(pat),
150 };
151
152 let var_head = first_node_text(var);
141 153
142 pat_head == var_head 154 pat_head == var_head
143} 155}