From 050c592b8ca4a4ad288a49267531a37e4598535a Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Thu, 27 May 2021 02:00:23 +0300 Subject: [PATCH] Exclude inherent traits more eagerly --- crates/ide_db/src/helpers/import_assets.rs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/crates/ide_db/src/helpers/import_assets.rs b/crates/ide_db/src/helpers/import_assets.rs index 91d6a466510..ae52dd8bb87 100644 --- a/crates/ide_db/src/helpers/import_assets.rs +++ b/crates/ide_db/src/helpers/import_assets.rs @@ -420,6 +420,8 @@ fn trait_applicable_items( let db = sema.db; + let related_dyn_traits = + trait_candidate.receiver_ty.applicable_inherent_traits(db).collect::>(); let mut required_assoc_items = FxHashSet::default(); let trait_candidates = items_locator::items_with_name( sema, @@ -431,13 +433,15 @@ fn trait_applicable_items( .filter_map(|input| item_as_assoc(db, input)) .filter_map(|assoc| { let assoc_item_trait = assoc.containing_trait(db)?; - required_assoc_items.insert(assoc); - Some(assoc_item_trait.into()) + if related_dyn_traits.contains(&assoc_item_trait) { + None + } else { + required_assoc_items.insert(assoc); + Some(assoc_item_trait.into()) + } }) .collect(); - let related_dyn_traits = - trait_candidate.receiver_ty.applicable_inherent_traits(db).collect::>(); let mut located_imports = FxHashSet::default(); if trait_assoc_item { @@ -454,10 +458,6 @@ fn trait_applicable_items( } } 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( @@ -480,9 +480,6 @@ fn trait_applicable_items( let assoc = function.as_assoc_item(db)?; if required_assoc_items.contains(&assoc) { 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(