Skip to content

Commit 48027bf

Browse files
committed
handle trait in function
Signed-off-by: Hayashi Mikihiro <[email protected]>
1 parent 55dd211 commit 48027bf

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

crates/ide-assists/src/handlers/remove_unused_imports.rs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -103,29 +103,12 @@ pub(crate) fn remove_unused_imports(acc: &mut Assists, ctx: &AssistContext<'_>)
103103
})
104104
.any(|d| used_once_in_scope(ctx, d, u.rename(), scope))
105105
{
106-
return Some(u);
106+
Some(u)
107107
} 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
128109
}
110+
} else {
111+
is_path_per_ns_unused_in_scope(ctx, &u, scope, &res).then_some(u)
129112
}
130113
})
131114
.peekable();
@@ -148,6 +131,25 @@ pub(crate) fn remove_unused_imports(acc: &mut Assists, ctx: &AssistContext<'_>)
148131
}
149132
}
150133

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+
151153
fn is_path_unused_in_scope(
152154
ctx: &AssistContext<'_>,
153155
u: &ast::UseTree,

0 commit comments

Comments
 (0)