9017: internal: Reduce the number of traits passed through chalk during applicable trait lookup r=SomeoneToIgnore a=SomeoneToIgnore

Inherent traits can be omitted before trait solving, presumably slightly helping https://github.com/rust-analyzer/rust-analyzer/issues/7542 and slightly simplifying the code.

Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
This commit is contained in:
bors[bot] 2021-05-26 23:06:59 +00:00 committed by GitHub
commit d6ed315806
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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::<FxHashSet<_>>();
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::<FxHashSet<_>>();
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(