@@ -315,53 +315,44 @@ impl Ctx<'_> {
315
315
}
316
316
317
317
fn transform_path ( & self , path : & SyntaxNode ) -> SyntaxNode {
318
- fn find_child_paths ( root_path : & SyntaxNode ) -> Vec < ast:: Path > {
319
- let mut result = Vec :: new ( ) ;
318
+ fn find_child_paths_and_ident_pats ( root_path : & SyntaxNode ) -> Vec < Either < ast:: Path , ast :: IdentPat > > {
319
+ let mut result: Vec < Either < ast :: Path , ast :: IdentPat > > = Vec :: new ( ) ;
320
320
for child in root_path. children ( ) {
321
321
if let Some ( child_path) = ast:: Path :: cast ( child. clone ( ) ) {
322
- result. push ( child_path) ;
322
+ result. push ( either:: Left ( child_path) ) ;
323
+ } else if let Some ( child_ident_pat) = ast:: IdentPat :: cast ( child. clone ( ) ) {
324
+ result. push ( either:: Right ( child_ident_pat) ) ;
323
325
} else {
324
- result. extend ( find_child_paths ( & child) ) ;
325
- }
326
- }
327
- result
328
- }
329
- fn find_child_ident_pats ( root_path : & SyntaxNode ) -> Vec < ast:: IdentPat > {
330
- let mut result = Vec :: new ( ) ;
331
- for child in root_path. children ( ) {
332
- if let Some ( child_ident_pat) = ast:: IdentPat :: cast ( child. clone ( ) ) {
333
- result. push ( child_ident_pat) ;
334
- } else {
335
- result. extend ( find_child_ident_pats ( & child) ) ;
326
+ result. extend ( find_child_paths_and_ident_pats ( & child) ) ;
336
327
}
337
328
}
338
329
result
339
330
}
340
331
341
332
let root_path = path. clone_subtree ( ) ;
342
333
343
- let result = find_child_paths ( & root_path) ;
334
+ let result = find_child_paths_and_ident_pats ( & root_path) ;
344
335
let mut editor = SyntaxEditor :: new ( root_path. clone ( ) ) ;
345
336
for sub_path in result {
346
337
let new = self . transform_path ( sub_path. syntax ( ) ) ;
347
338
editor. replace ( sub_path. syntax ( ) , new) ;
348
339
}
349
340
350
- let ident_result = find_child_ident_pats ( & root_path) ;
351
- for ident_pat in ident_result {
352
- if let Some ( new) = self . transform_ident_pat ( & ident_pat) {
353
- editor. replace ( ident_pat. syntax ( ) , new. syntax ( ) ) ;
354
- }
355
- }
356
-
357
341
let update_sub_item = editor. finish ( ) . new_root ( ) . clone ( ) . clone_subtree ( ) ;
358
- let item = find_child_paths ( & update_sub_item) ;
342
+ let item = find_child_paths_and_ident_pats ( & update_sub_item) ;
359
343
let mut editor = SyntaxEditor :: new ( update_sub_item) ;
360
344
for sub_path in item {
361
- self . transform_path_ ( & mut editor, & sub_path) ;
345
+ self . transform_path_or_ident_pat ( & mut editor, & sub_path) ;
362
346
}
363
347
editor. finish ( ) . new_root ( ) . clone ( )
364
348
}
349
+
350
+ fn transform_path_or_ident_pat ( & self , editor : & mut SyntaxEditor , item : & Either < ast:: Path , ast:: IdentPat > ) -> Option < ( ) > {
351
+ match item {
352
+ Either :: Left ( path) => self . transform_path_ ( editor, path) ,
353
+ Either :: Right ( ident_pat) => self . transform_ident_pat ( editor, ident_pat)
354
+ }
355
+ }
365
356
366
357
fn transform_path_ ( & self , editor : & mut SyntaxEditor , path : & ast:: Path ) -> Option < ( ) > {
367
358
if path. qualifier ( ) . is_some ( ) {
@@ -537,7 +528,7 @@ impl Ctx<'_> {
537
528
Some ( ( ) )
538
529
}
539
530
540
- fn transform_ident_pat ( & self , ident_pat : & ast:: IdentPat ) -> Option < ast :: Path > {
531
+ fn transform_ident_pat ( & self , editor : & mut SyntaxEditor , ident_pat : & ast:: IdentPat ) -> Option < ( ) > {
541
532
let name = ident_pat. name ( ) ?;
542
533
543
534
let temp_path = make:: path_from_text ( & name. text ( ) ) ;
@@ -554,7 +545,8 @@ impl Ctx<'_> {
554
545
} ;
555
546
let found_path = self . target_module . find_path ( self . source_scope . db , def, cfg) ?;
556
547
let res = mod_path_to_ast ( & found_path, self . target_edition ) . clone_for_update ( ) ;
557
- Some ( res)
548
+ editor. replace ( ident_pat. syntax ( ) , res. syntax ( ) ) ;
549
+ Some ( ( ) )
558
550
}
559
551
_ => None ,
560
552
}
0 commit comments