@@ -103,29 +103,12 @@ pub(crate) fn remove_unused_imports(acc: &mut Assists, ctx: &AssistContext<'_>)
103
103
} )
104
104
. any ( |d| used_once_in_scope ( ctx, d, u. rename ( ) , scope) )
105
105
{
106
- return Some ( u) ;
106
+ Some ( u)
107
107
} else {
108
- return None ;
109
- }
110
- }
111
- match res {
112
- PathResolutionPerNs {
113
- type_ns : Some ( PathResolution :: Def ( ModuleDef :: Trait ( ref t) ) ) ,
114
- value_ns,
115
- macro_ns,
116
- } => {
117
- // If the trait or any item is used.
118
- if is_trait_unused_in_scope ( ctx, & u, scope, t) {
119
- let path = [ value_ns, macro_ns] ;
120
- is_path_unused_in_scope ( ctx, & u, scope, & path) . then_some ( u)
121
- } else {
122
- None
123
- }
124
- }
125
- PathResolutionPerNs { type_ns, value_ns, macro_ns } => {
126
- let path = [ type_ns, value_ns, macro_ns] ;
127
- is_path_unused_in_scope ( ctx, & u, scope, & path) . then_some ( u)
108
+ None
128
109
}
110
+ } else {
111
+ is_path_per_ns_unused_in_scope ( ctx, & u, scope, & res) . then_some ( u)
129
112
}
130
113
} )
131
114
. peekable ( ) ;
@@ -148,6 +131,25 @@ pub(crate) fn remove_unused_imports(acc: &mut Assists, ctx: &AssistContext<'_>)
148
131
}
149
132
}
150
133
134
+ fn is_path_per_ns_unused_in_scope (
135
+ ctx : & AssistContext < ' _ > ,
136
+ u : & ast:: UseTree ,
137
+ scope : & mut Vec < SearchScope > ,
138
+ path : & PathResolutionPerNs ,
139
+ ) -> bool {
140
+ if let Some ( PathResolution :: Def ( ModuleDef :: Trait ( ref t) ) ) = path. type_ns {
141
+ if is_trait_unused_in_scope ( ctx, u, scope, t) {
142
+ let path = [ path. value_ns , path. macro_ns ] ;
143
+ is_path_unused_in_scope ( ctx, u, scope, & path)
144
+ } else {
145
+ false
146
+ }
147
+ } else {
148
+ let path = [ path. type_ns , path. value_ns , path. macro_ns ] ;
149
+ is_path_unused_in_scope ( ctx, u, scope, & path)
150
+ }
151
+ }
152
+
151
153
fn is_path_unused_in_scope (
152
154
ctx : & AssistContext < ' _ > ,
153
155
u : & ast:: UseTree ,
0 commit comments