1
1
use std:: iter:: { self , Peekable } ;
2
- use std:: ops:: Deref ;
3
- use std:: rc:: Rc ;
4
2
5
3
use either:: Either ;
6
4
use hir:: { sym, Adt , Crate , HasAttrs , ImportPathConfig , ModuleDef , Semantics } ;
@@ -78,10 +76,7 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>)
78
76
79
77
let cfg = ctx. config . import_path_config ( ) ;
80
78
81
- // As `make` is borrowed by the closure that builds `missing_pats`, this is needed
82
- // to satisfy the borrow checker.
83
- let make = Rc :: new ( SyntaxFactory :: new ( ) ) ;
84
- let make_weak = Rc :: downgrade ( & make) ;
79
+ let make = SyntaxFactory :: new ( ) ;
85
80
86
81
let module = ctx. sema . scope ( expr. syntax ( ) ) ?. module ( ) ;
87
82
let ( mut missing_pats, is_non_exhaustive, has_hidden_variants) : (
@@ -99,9 +94,8 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>)
99
94
let missing_pats = variants
100
95
. into_iter ( )
101
96
. filter_map ( |variant| {
102
- let make = make_weak. upgrade ( ) ?;
103
97
Some ( (
104
- build_pat ( ctx, make, module, variant, cfg) ?,
98
+ build_pat ( ctx, & make, module, variant, cfg) ?,
105
99
variant. should_be_hidden ( ctx. db ( ) , module. krate ( ) ) ,
106
100
) )
107
101
} )
@@ -148,17 +142,15 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>)
148
142
. into_iter ( )
149
143
. multi_cartesian_product ( )
150
144
. inspect ( |_| cov_mark:: hit!( add_missing_match_arms_lazy_computation) )
151
- . filter_map ( |variants| {
145
+ . map ( |variants| {
152
146
let is_hidden = variants
153
147
. iter ( )
154
148
. any ( |variant| variant. should_be_hidden ( ctx. db ( ) , module. krate ( ) ) ) ;
155
- let patterns = variants. into_iter ( ) . filter_map ( |variant| {
156
- make_weak . upgrade ( ) . and_then ( |make| build_pat ( ctx , make , module , variant , cfg ) )
157
- } ) ;
149
+ let patterns = variants
150
+ . into_iter ( )
151
+ . filter_map ( |variant| build_pat ( ctx , & make , module , variant , cfg ) ) ;
158
152
159
- make_weak
160
- . upgrade ( )
161
- . map ( |make| ( ast:: Pat :: from ( make. tuple_pat ( patterns) ) , is_hidden) )
153
+ ( ast:: Pat :: from ( make. tuple_pat ( patterns) ) , is_hidden)
162
154
} )
163
155
. filter ( |( variant_pat, _) | is_variant_missing ( & top_lvl_pats, variant_pat) ) ;
164
156
(
@@ -183,17 +175,15 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>)
183
175
. into_iter ( )
184
176
. multi_cartesian_product ( )
185
177
. inspect ( |_| cov_mark:: hit!( add_missing_match_arms_lazy_computation) )
186
- . filter_map ( |variants| {
178
+ . map ( |variants| {
187
179
let is_hidden = variants
188
180
. iter ( )
189
181
. any ( |variant| variant. should_be_hidden ( ctx. db ( ) , module. krate ( ) ) ) ;
190
- let patterns = variants. into_iter ( ) . filter_map ( |variant| {
191
- make_weak . upgrade ( ) . and_then ( |make| build_pat ( ctx , make , module , variant , cfg ) )
192
- } ) ;
182
+ let patterns = variants
183
+ . into_iter ( )
184
+ . filter_map ( |variant| build_pat ( ctx , & make , module , variant , cfg ) ) ;
193
185
194
- make_weak
195
- . upgrade ( )
196
- . map ( |make| ( ast:: Pat :: from ( make. slice_pat ( patterns) ) , is_hidden) )
186
+ ( ast:: Pat :: from ( make. slice_pat ( patterns) ) , is_hidden)
197
187
} )
198
188
. filter ( |( variant_pat, _) | is_variant_missing ( & top_lvl_pats, variant_pat) ) ;
199
189
(
@@ -303,7 +293,7 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>)
303
293
}
304
294
}
305
295
306
- editor. add_mappings ( Rc :: into_inner ( make) . unwrap ( ) . finish_with_mappings ( ) ) ;
296
+ editor. add_mappings ( make. take ( ) ) ;
307
297
builder. add_file_edits ( ctx. file_id ( ) , editor) ;
308
298
} ,
309
299
)
@@ -458,7 +448,7 @@ fn resolve_array_of_enum_def(
458
448
459
449
fn build_pat (
460
450
ctx : & AssistContext < ' _ > ,
461
- make : impl Deref < Target = SyntaxFactory > ,
451
+ make : & SyntaxFactory ,
462
452
module : hir:: Module ,
463
453
var : ExtendedVariant ,
464
454
cfg : ImportPathConfig ,
0 commit comments