Skip to content

fix: Removing all unused imports removes used imports for imports used for Derive macros#19793

Merged
ChayimFriedman2 merged 4 commits into
rust-lang:masterfrom
Hmikihiro:unused_import_conlict_derive
May 15, 2025
Merged

fix: Removing all unused imports removes used imports for imports used for Derive macros#19793
ChayimFriedman2 merged 4 commits into
rust-lang:masterfrom
Hmikihiro:unused_import_conlict_derive

Conversation

@Hmikihiro

@Hmikihiro Hmikihiro commented May 14, 2025

Copy link
Copy Markdown
Contributor

fix: #19119

2025-05-15.1.05.49.mov

…d for Derive macros

Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 14, 2025
Comment on lines -1638 to +1669
if prefer_value_ns { values().or_else(types) } else { types().or_else(values) }
.or_else(items)
.or_else(macros)
if resolve_per_ns {
PathResolutionPerNs {
type_ns: types().or_else(items),
value_ns: values(),
macro_ns: macros(),
}
} else {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I resolve type per namespace and make Struct for keep with split.

Comment on lines +1216 to +1234
pub(crate) fn resolve_hir_path_per_ns(
&self,
db: &dyn HirDatabase,
path: &ast::Path,
) -> Option<PathResolutionPerNs> {
let mut collector = ExprCollector::new(db, self.resolver.module(), self.file_id);
let hir_path =
collector.lower_path(path.clone(), &mut ExprCollector::impl_trait_error_allocator)?;
let store = collector.store.finish();
Some(resolve_hir_path_(
db,
&self.resolver,
&hir_path,
false,
name_hygiene(db, InFile::new(self.file_id, path.syntax())),
Some(&store),
true,
))
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we check unused import, we check only tail of path.

use foo::bar;
         ^^^

So I check only by resolve_hir_path_ instead of resolve_path

@ChayimFriedman2 ChayimFriedman2 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good, I propose a few minor changes.

Comment thread crates/hir/src/semantics.rs Outdated
Comment thread crates/ide-assists/src/handlers/remove_unused_imports.rs Outdated
Comment thread crates/ide-assists/src/handlers/remove_unused_imports.rs Outdated
Hmikihiro added 3 commits May 15, 2025 13:18
Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>
Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>
Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>

@ChayimFriedman2 ChayimFriedman2 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ChayimFriedman2
ChayimFriedman2 added this pull request to the merge queue May 15, 2025
Merged via the queue into rust-lang:master with commit 15ce258 May 15, 2025
@Hmikihiro
Hmikihiro deleted the unused_import_conlict_derive branch July 22, 2025 05:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Removing all unused imports removes used imports for imports used for Derive macros

3 participants