aboutsummaryrefslogtreecommitdiff
path: root/crates/hir
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir')
-rw-r--r--crates/hir/src/lib.rs23
1 files changed, 19 insertions, 4 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index f0bc2c7b9..ad79a79f8 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -60,6 +60,7 @@ use hir_ty::{
60 InEnvironment, Interner, Obligation, ProjectionPredicate, ProjectionTy, Scalar, Substs, Ty, 60 InEnvironment, Interner, Obligation, ProjectionPredicate, ProjectionTy, Scalar, Substs, Ty,
61 TyDefId, TyKind, TyVariableKind, 61 TyDefId, TyKind, TyVariableKind,
62}; 62};
63use itertools::Itertools;
63use rustc_hash::FxHashSet; 64use rustc_hash::FxHashSet;
64use stdx::{format_to, impl_from}; 65use stdx::{format_to, impl_from};
65use syntax::{ 66use syntax::{
@@ -141,7 +142,6 @@ impl Crate {
141 .collect() 142 .collect()
142 } 143 }
143 144
144 // FIXME: add `transitive_reverse_dependencies`.
145 pub fn reverse_dependencies(self, db: &dyn HirDatabase) -> Vec<Crate> { 145 pub fn reverse_dependencies(self, db: &dyn HirDatabase) -> Vec<Crate> {
146 let crate_graph = db.crate_graph(); 146 let crate_graph = db.crate_graph();
147 crate_graph 147 crate_graph
@@ -153,6 +153,14 @@ impl Crate {
153 .collect() 153 .collect()
154 } 154 }
155 155
156 pub fn transitive_reverse_dependencies(self, db: &dyn HirDatabase) -> Vec<Crate> {
157 db.crate_graph()
158 .transitive_reverse_dependencies(self.id)
159 .into_iter()
160 .map(|id| Crate { id })
161 .collect()
162 }
163
156 pub fn root_module(self, db: &dyn HirDatabase) -> Module { 164 pub fn root_module(self, db: &dyn HirDatabase) -> Module {
157 let def_map = db.crate_def_map(self.id); 165 let def_map = db.crate_def_map(self.id);
158 Module { id: def_map.module_id(def_map.root()) } 166 Module { id: def_map.module_id(def_map.root()) }
@@ -1541,11 +1549,17 @@ impl Impl {
1541 }; 1549 };
1542 1550
1543 let mut all = Vec::new(); 1551 let mut all = Vec::new();
1544 def_crates.into_iter().for_each(|id| { 1552 def_crates.iter().for_each(|&id| {
1545 all.extend(db.inherent_impls_in_crate(id).all_impls().map(Self::from).filter(filter)) 1553 all.extend(db.inherent_impls_in_crate(id).all_impls().map(Self::from).filter(filter))
1546 }); 1554 });
1547 let fp = TyFingerprint::for_impl(&ty.value); 1555 let fp = TyFingerprint::for_impl(&ty.value);
1548 for id in db.crate_graph().iter() { 1556 for id in def_crates
1557 .iter()
1558 .flat_map(|&id| Crate { id }.transitive_reverse_dependencies(db))
1559 .map(|Crate { id }| id)
1560 .chain(def_crates.iter().copied())
1561 .unique()
1562 {
1549 match fp { 1563 match fp {
1550 Some(fp) => all.extend( 1564 Some(fp) => all.extend(
1551 db.trait_impls_in_crate(id).for_self_ty(fp).map(Self::from).filter(filter), 1565 db.trait_impls_in_crate(id).for_self_ty(fp).map(Self::from).filter(filter),
@@ -1560,7 +1574,8 @@ impl Impl {
1560 pub fn all_for_trait(db: &dyn HirDatabase, trait_: Trait) -> Vec<Impl> { 1574 pub fn all_for_trait(db: &dyn HirDatabase, trait_: Trait) -> Vec<Impl> {
1561 let krate = trait_.module(db).krate(); 1575 let krate = trait_.module(db).krate();
1562 let mut all = Vec::new(); 1576 let mut all = Vec::new();
1563 for Crate { id } in krate.reverse_dependencies(db).into_iter().chain(Some(krate)) { 1577 for Crate { id } in krate.transitive_reverse_dependencies(db).into_iter().chain(Some(krate))
1578 {
1564 let impls = db.trait_impls_in_crate(id); 1579 let impls = db.trait_impls_in_crate(id);
1565 all.extend(impls.for_trait(trait_.id).map(Self::from)) 1580 all.extend(impls.for_trait(trait_.id).map(Self::from))
1566 } 1581 }