diff options
| author | Hayashi Mikihiro <34ttrweoewiwe28@gmail.com> | 2025-05-15 15:12:31 +0900 |
|---|---|---|
| committer | Hayashi Mikihiro <34ttrweoewiwe28@gmail.com> | 2025-05-15 15:12:31 +0900 |
| commit | 034d2a2fe778d0effe9532775f08a5652159b207 (patch) | |
| tree | 1d3264e6412df40f41058e9ab77508a6cda8e8f4 /src | |
| parent | 2c55a78848cebf3bede3339362bbfcbc6c18fa8c (diff) | |
| download | rust-034d2a2fe778d0effe9532775f08a5652159b207.tar.gz rust-034d2a2fe778d0effe9532775f08a5652159b207.zip | |
handle trait in function
Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/tools/rust-analyzer/crates/ide-assists/src/handlers/remove_unused_imports.rs | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/remove_unused_imports.rs b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/remove_unused_imports.rs index 994e7c446cc..16debc4d728 100644 --- a/src/tools/rust-analyzer/crates/ide-assists/src/handlers/remove_unused_imports.rs +++ b/src/tools/rust-analyzer/crates/ide-assists/src/handlers/remove_unused_imports.rs @@ -103,29 +103,12 @@ pub(crate) fn remove_unused_imports(acc: &mut Assists, ctx: &AssistContext<'_>) }) .any(|d| used_once_in_scope(ctx, d, u.rename(), scope)) { - return Some(u); + Some(u) } else { - return None; - } - } - match res { - PathResolutionPerNs { - type_ns: Some(PathResolution::Def(ModuleDef::Trait(ref t))), - value_ns, - macro_ns, - } => { - // If the trait or any item is used. - if is_trait_unused_in_scope(ctx, &u, scope, t) { - let path = [value_ns, macro_ns]; - is_path_unused_in_scope(ctx, &u, scope, &path).then_some(u) - } else { - None - } - } - PathResolutionPerNs { type_ns, value_ns, macro_ns } => { - let path = [type_ns, value_ns, macro_ns]; - is_path_unused_in_scope(ctx, &u, scope, &path).then_some(u) + None } + } else { + is_path_per_ns_unused_in_scope(ctx, &u, scope, &res).then_some(u) } }) .peekable(); @@ -148,6 +131,25 @@ pub(crate) fn remove_unused_imports(acc: &mut Assists, ctx: &AssistContext<'_>) } } +fn is_path_per_ns_unused_in_scope( + ctx: &AssistContext<'_>, + u: &ast::UseTree, + scope: &mut Vec<SearchScope>, + path: &PathResolutionPerNs, +) -> bool { + if let Some(PathResolution::Def(ModuleDef::Trait(ref t))) = path.type_ns { + if is_trait_unused_in_scope(ctx, u, scope, t) { + let path = [path.value_ns, path.macro_ns]; + is_path_unused_in_scope(ctx, u, scope, &path) + } else { + false + } + } else { + let path = [path.type_ns, path.value_ns, path.macro_ns]; + is_path_unused_in_scope(ctx, u, scope, &path) + } +} + fn is_path_unused_in_scope( ctx: &AssistContext<'_>, u: &ast::UseTree, |
