From 41f5471f3e5dab3da345361a0924391d6267373f Mon Sep 17 00:00:00 2001 From: Toby Dimmick Date: Sun, 14 Jun 2020 22:44:28 +0100 Subject: fill_match_arms bind pattern implementation --- crates/ra_assists/src/handlers/fill_match_arms.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'crates/ra_assists/src') 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, var: &Pat) -> bool { } fn does_pat_match_variant(pat: &Pat, var: &Pat) -> bool { - let pat_head = pat.syntax().first_child().map(|node| node.text()); - let var_head = var.syntax().first_child().map(|node| node.text()); + let first_node_text = |pat: &Pat| pat.syntax().first_child().map(|node| node.text()); + + let pat_head = match pat { + Pat::BindPat(bind_pat) => { + if let Some(p) = bind_pat.pat() { + first_node_text(&p) + } else { + return false; + } + } + pat => first_node_text(pat), + }; + + let var_head = first_node_text(var); pat_head == var_head } -- cgit v1.2.3