aboutsummaryrefslogtreecommitdiff
path: root/crates/assists/src/handlers/replace_if_let_with_match.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/assists/src/handlers/replace_if_let_with_match.rs')
-rw-r--r--crates/assists/src/handlers/replace_if_let_with_match.rs27
1 files changed, 5 insertions, 22 deletions
diff --git a/crates/assists/src/handlers/replace_if_let_with_match.rs b/crates/assists/src/handlers/replace_if_let_with_match.rs
index abebd4b6a..aee880625 100644
--- a/crates/assists/src/handlers/replace_if_let_with_match.rs
+++ b/crates/assists/src/handlers/replace_if_let_with_match.rs
@@ -5,12 +5,15 @@ use syntax::{
5 ast::{ 5 ast::{
6 self, 6 self,
7 edit::{AstNodeEdit, IndentLevel}, 7 edit::{AstNodeEdit, IndentLevel},
8 make, Pat, 8 make,
9 }, 9 },
10 AstNode, 10 AstNode,
11}; 11};
12 12
13use crate::{utils::unwrap_trivial_block, AssistContext, AssistId, AssistKind, Assists}; 13use crate::{
14 utils::{does_pat_match_variant, unwrap_trivial_block},
15 AssistContext, AssistId, AssistKind, Assists,
16};
14 17
15// Assist: replace_if_let_with_match 18// Assist: replace_if_let_with_match
16// 19//
@@ -87,26 +90,6 @@ pub(crate) fn replace_if_let_with_match(acc: &mut Assists, ctx: &AssistContext)
87 ) 90 )
88} 91}
89 92
90fn does_pat_match_variant(pat: &Pat, var: &Pat) -> bool {
91 let first_node_text = |pat: &Pat| pat.syntax().first_child().map(|node| node.text());
92
93 let pat_head = match pat {
94 Pat::IdentPat(bind_pat) => {
95 if let Some(p) = bind_pat.pat() {
96 first_node_text(&p)
97 } else {
98 return pat.syntax().text() == var.syntax().text();
99 }
100 }
101 pat => first_node_text(pat),
102 };
103
104 let var_head = first_node_text(var);
105 println!("{:?} {:?}", pat_head, var_head);
106
107 pat_head == var_head
108}
109
110// Assist: replace_match_with_if_let 93// Assist: replace_match_with_if_let
111// 94//
112// Replaces a binary `match` with a wildcard pattern and no guards with an `if let` expression. 95// Replaces a binary `match` with a wildcard pattern and no guards with an `if let` expression.