File tree Expand file tree Collapse file tree 2 files changed +48
-1
lines changed Expand file tree Collapse file tree 2 files changed +48
-1
lines changed Original file line number Diff line number Diff line change @@ -776,6 +776,40 @@ mod z {
776776 ) ;
777777 }
778778
779+ #[ test]
780+ fn remove_unused_fixes_nested_self ( ) {
781+ check_assist (
782+ remove_unused_imports,
783+ r#"
784+ mod inner {
785+ pub struct X();
786+ pub struct Y();
787+ }
788+
789+ mod z {
790+ use super::inner::{self, X}$0;
791+
792+ fn f() {
793+ let y = inner::Y();
794+ }
795+ }
796+ "# ,
797+ r#"mod inner {
798+ pub struct X();
799+ pub struct Y();
800+ }
801+
802+ mod z {
803+ use super::inner::{self};
804+
805+ fn f() {
806+ let y = inner::Y();
807+ }
808+ }
809+ "# ,
810+ ) ;
811+ }
812+
779813 #[ test]
780814 fn dont_remove_used_glob ( ) {
781815 check_assist_not_applicable (
Original file line number Diff line number Diff line change @@ -376,11 +376,24 @@ impl ast::UseTreeList {
376376 . filter_map ( |it| it. into_token ( ) . filter ( |it| it. kind ( ) == T ! [ , ] ) )
377377 }
378378
379+ pub fn is_just_self ( & self ) -> bool {
380+ if let Some ( ( single_subtree, ) ) = self . use_trees ( ) . collect_tuple ( ) {
381+ fn path_is_self ( path : & ast:: Path ) -> bool {
382+ path. segment ( ) . and_then ( |seg| seg. self_token ( ) ) . is_some ( )
383+ && path. qualifier ( ) . is_none ( )
384+ }
385+
386+ single_subtree. path ( ) . as_ref ( ) . map_or ( false , path_is_self)
387+ } else {
388+ false
389+ }
390+ }
391+
379392 /// Remove the unnecessary braces in current `UseTreeList`
380393 pub fn remove_unnecessary_braces ( mut self ) {
381394 let remove_brace_in_use_tree_list = |u : & ast:: UseTreeList | {
382395 let use_tree_count = u. use_trees ( ) . count ( ) ;
383- if use_tree_count == 1 {
396+ if use_tree_count == 1 && !u . is_just_self ( ) {
384397 if let Some ( a) = u. l_curly_token ( ) {
385398 ted:: remove ( a)
386399 }
You can’t perform that action at this time.
0 commit comments