aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorKirill Bulatov <[email protected]>2021-05-27 00:00:23 +0100
committerKirill Bulatov <[email protected]>2021-05-27 00:00:23 +0100
commit050c592b8ca4a4ad288a49267531a37e4598535a (patch)
tree0cf92a4d1fc5945202fe3e0fad8d0903abf7aa7c /crates
parentb4015b6aaa0dd80f5c85c7ed03e83d0d16042264 (diff)
Exclude inherent traits more eagerly
Diffstat (limited to 'crates')
-rw-r--r--crates/ide_db/src/helpers/import_assets.rs19
1 files 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 91d6a4665..ae52dd8bb 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(
420 420
421 let db = sema.db; 421 let db = sema.db;
422 422
423 let related_dyn_traits =
424 trait_candidate.receiver_ty.applicable_inherent_traits(db).collect::<FxHashSet<_>>();
423 let mut required_assoc_items = FxHashSet::default(); 425 let mut required_assoc_items = FxHashSet::default();
424 let trait_candidates = items_locator::items_with_name( 426 let trait_candidates = items_locator::items_with_name(
425 sema, 427 sema,
@@ -431,13 +433,15 @@ fn trait_applicable_items(
431 .filter_map(|input| item_as_assoc(db, input)) 433 .filter_map(|input| item_as_assoc(db, input))
432 .filter_map(|assoc| { 434 .filter_map(|assoc| {
433 let assoc_item_trait = assoc.containing_trait(db)?; 435 let assoc_item_trait = assoc.containing_trait(db)?;
434 required_assoc_items.insert(assoc); 436 if related_dyn_traits.contains(&assoc_item_trait) {
435 Some(assoc_item_trait.into()) 437 None
438 } else {
439 required_assoc_items.insert(assoc);
440 Some(assoc_item_trait.into())
441 }
436 }) 442 })
437 .collect(); 443 .collect();
438 444
439 let related_dyn_traits =
440 trait_candidate.receiver_ty.applicable_inherent_traits(db).collect::<FxHashSet<_>>();
441 let mut located_imports = FxHashSet::default(); 445 let mut located_imports = FxHashSet::default();
442 446
443 if trait_assoc_item { 447 if trait_assoc_item {
@@ -454,10 +458,6 @@ fn trait_applicable_items(
454 } 458 }
455 } 459 }
456 let located_trait = assoc.containing_trait(db)?; 460 let located_trait = assoc.containing_trait(db)?;
457 if related_dyn_traits.contains(&located_trait) {
458 return None;
459 }
460
461 let trait_item = ItemInNs::from(ModuleDef::from(located_trait)); 461 let trait_item = ItemInNs::from(ModuleDef::from(located_trait));
462 let original_item = assoc_to_item(assoc); 462 let original_item = assoc_to_item(assoc);
463 located_imports.insert(LocatedImport::new( 463 located_imports.insert(LocatedImport::new(
@@ -480,9 +480,6 @@ fn trait_applicable_items(
480 let assoc = function.as_assoc_item(db)?; 480 let assoc = function.as_assoc_item(db)?;
481 if required_assoc_items.contains(&assoc) { 481 if required_assoc_items.contains(&assoc) {
482 let located_trait = assoc.containing_trait(db)?; 482 let located_trait = assoc.containing_trait(db)?;
483 if related_dyn_traits.contains(&located_trait) {
484 return None;
485 }
486 let trait_item = ItemInNs::from(ModuleDef::from(located_trait)); 483 let trait_item = ItemInNs::from(ModuleDef::from(located_trait));
487 let original_item = assoc_to_item(assoc); 484 let original_item = assoc_to_item(assoc);
488 located_imports.insert(LocatedImport::new( 485 located_imports.insert(LocatedImport::new(