1
1
use std:: iter:: { self , successors} ;
2
2
3
3
use either:: Either ;
4
- use ide_db:: { defs:: NameClass , ty_filter:: TryEnum , RootDatabase } ;
4
+ use ide_db:: {
5
+ defs:: NameClass ,
6
+ helpers:: node_ext:: { is_pattern_cond, single_let} ,
7
+ ty_filter:: TryEnum ,
8
+ RootDatabase ,
9
+ } ;
5
10
use syntax:: {
6
11
ast:: {
7
12
self ,
@@ -61,7 +66,7 @@ pub(crate) fn replace_if_let_with_match(acc: &mut Assists, ctx: &AssistContext)
61
66
}
62
67
} ) ;
63
68
let scrutinee_to_be_expr = if_expr. condition ( ) ?;
64
- let scrutinee_to_be_expr = match scrutinee_to_be_expr. single_let ( ) {
69
+ let scrutinee_to_be_expr = match single_let ( scrutinee_to_be_expr. clone ( ) ) {
65
70
Some ( cond) => cond. expr ( ) ?,
66
71
None => scrutinee_to_be_expr,
67
72
} ;
@@ -70,7 +75,7 @@ pub(crate) fn replace_if_let_with_match(acc: &mut Assists, ctx: &AssistContext)
70
75
let mut cond_bodies = Vec :: new ( ) ;
71
76
for if_expr in if_exprs {
72
77
let cond = if_expr. condition ( ) ?;
73
- let cond = match cond. single_let ( ) {
78
+ let cond = match single_let ( cond. clone ( ) ) {
74
79
Some ( let_) => {
75
80
let pat = let_. pat ( ) ?;
76
81
let expr = let_. expr ( ) ?;
@@ -84,7 +89,7 @@ pub(crate) fn replace_if_let_with_match(acc: &mut Assists, ctx: &AssistContext)
84
89
Either :: Left ( pat)
85
90
}
86
91
// Multiple `let`, unsupported.
87
- None if cond. is_pattern_cond ( ) => return None ,
92
+ None if is_pattern_cond ( cond. clone ( ) ) => return None ,
88
93
None => Either :: Right ( cond) ,
89
94
} ;
90
95
let body = if_expr. then_branch ( ) ?;
0 commit comments