From 739edfd5cf6d1f5ac1ec6dbc28fc7943b3936e24 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Thu, 15 Apr 2021 23:31:42 +0300 Subject: Exclude inherent traits from flyimports --- crates/ide_db/src/helpers/import_assets.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'crates/ide_db') diff --git a/crates/ide_db/src/helpers/import_assets.rs b/crates/ide_db/src/helpers/import_assets.rs index 8ce648367..91d6a4665 100644 --- a/crates/ide_db/src/helpers/import_assets.rs +++ b/crates/ide_db/src/helpers/import_assets.rs @@ -436,6 +436,8 @@ fn trait_applicable_items( }) .collect(); + let related_dyn_traits = + trait_candidate.receiver_ty.applicable_inherent_traits(db).collect::>(); let mut located_imports = FxHashSet::default(); if trait_assoc_item { @@ -451,12 +453,16 @@ fn trait_applicable_items( return None; } } + let located_trait = assoc.containing_trait(db)?; + if related_dyn_traits.contains(&located_trait) { + return None; + } - let item = ItemInNs::from(ModuleDef::from(assoc.containing_trait(db)?)); + let trait_item = ItemInNs::from(ModuleDef::from(located_trait)); let original_item = assoc_to_item(assoc); located_imports.insert(LocatedImport::new( - mod_path(item)?, - item, + mod_path(trait_item)?, + trait_item, original_item, mod_path(original_item), )); @@ -473,11 +479,15 @@ fn trait_applicable_items( |_, function| { let assoc = function.as_assoc_item(db)?; if required_assoc_items.contains(&assoc) { - let item = ItemInNs::from(ModuleDef::from(assoc.containing_trait(db)?)); + let located_trait = assoc.containing_trait(db)?; + if related_dyn_traits.contains(&located_trait) { + return None; + } + let trait_item = ItemInNs::from(ModuleDef::from(located_trait)); let original_item = assoc_to_item(assoc); located_imports.insert(LocatedImport::new( - mod_path(item)?, - item, + mod_path(trait_item)?, + trait_item, original_item, mod_path(original_item), )); -- cgit v1.2.3