@@ -5,7 +5,6 @@ use crate::{
55 utils:: { find_insert_use_container, insert_use_statement} ,
66 AssistContext , AssistId , Assists ,
77} ;
8- use either:: Either ;
98
109// Assist: replace_qualified_name_with_use
1110//
@@ -56,14 +55,8 @@ pub(crate) fn replace_qualified_name_with_use(
5655 None => return ,
5756 } ;
5857 let mut rewriter = SyntaxRewriter :: default ( ) ;
59- match container {
60- Either :: Left ( l) => {
61- shorten_paths ( & mut rewriter, l. syntax ( ) . clone ( ) , hir_path. mod_path ( ) ) ;
62- }
63- Either :: Right ( r) => {
64- shorten_paths ( & mut rewriter, r. syntax ( ) . clone ( ) , hir_path. mod_path ( ) ) ;
65- }
66- }
58+ let syntax = container. either ( |l| l. syntax ( ) . clone ( ) , |r| r. syntax ( ) . clone ( ) ) ;
59+ shorten_paths ( & mut rewriter, syntax, hir_path. mod_path ( ) ) ;
6760 builder. rewrite ( rewriter) ;
6861 } ,
6962 )
@@ -90,7 +83,7 @@ fn collect_hir_path_segments(path: &hir::Path) -> Option<Vec<SmolStr>> {
9083}
9184
9285/// Adds replacements to `re` that shorten `path` in all descendants of `node`.
93- fn shorten_paths ( re : & mut SyntaxRewriter < ' static > , node : SyntaxNode , path : & ModPath ) {
86+ fn shorten_paths ( rewriter : & mut SyntaxRewriter < ' static > , node : SyntaxNode , path : & ModPath ) {
9487 for child in node. children ( ) {
9588 match_ast ! {
9689 match child {
@@ -101,12 +94,12 @@ fn shorten_paths(re: &mut SyntaxRewriter<'static>, node: SyntaxNode, path: &ModP
10194 ast:: Module ( _it) => continue ,
10295
10396 ast:: Path ( p) => {
104- match maybe_replace_path( re , & p, path) {
97+ match maybe_replace_path( rewriter , & p, path) {
10598 Some ( ( ) ) => { } ,
106- None => shorten_paths( re , p. syntax( ) . clone( ) , path) ,
99+ None => shorten_paths( rewriter , p. syntax( ) . clone( ) , path) ,
107100 }
108101 } ,
109- _ => shorten_paths( re , child, path) ,
102+ _ => shorten_paths( rewriter , child, path) ,
110103 }
111104 }
112105 }
0 commit comments