diff options
Diffstat (limited to 'crates/hir/src')
-rw-r--r-- | crates/hir/src/lib.rs | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index c5161dadd..079a5f7b8 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs | |||
@@ -58,6 +58,7 @@ use hir_ty::{ | |||
58 | InEnvironment, Interner, Obligation, ProjectionPredicate, ProjectionTy, Scalar, Substs, Ty, | 58 | InEnvironment, Interner, Obligation, ProjectionPredicate, ProjectionTy, Scalar, Substs, Ty, |
59 | TyDefId, TyKind, TyVariableKind, | 59 | TyDefId, TyKind, TyVariableKind, |
60 | }; | 60 | }; |
61 | use itertools::Itertools; | ||
61 | use rustc_hash::FxHashSet; | 62 | use rustc_hash::FxHashSet; |
62 | use stdx::{format_to, impl_from}; | 63 | use stdx::{format_to, impl_from}; |
63 | use syntax::{ | 64 | use syntax::{ |
@@ -139,7 +140,6 @@ impl Crate { | |||
139 | .collect() | 140 | .collect() |
140 | } | 141 | } |
141 | 142 | ||
142 | // FIXME: add `transitive_reverse_dependencies`. | ||
143 | pub fn reverse_dependencies(self, db: &dyn HirDatabase) -> Vec<Crate> { | 143 | pub fn reverse_dependencies(self, db: &dyn HirDatabase) -> Vec<Crate> { |
144 | let crate_graph = db.crate_graph(); | 144 | let crate_graph = db.crate_graph(); |
145 | crate_graph | 145 | crate_graph |
@@ -151,6 +151,14 @@ impl Crate { | |||
151 | .collect() | 151 | .collect() |
152 | } | 152 | } |
153 | 153 | ||
154 | pub fn transitive_reverse_dependencies(self, db: &dyn HirDatabase) -> Vec<Crate> { | ||
155 | db.crate_graph() | ||
156 | .transitive_reverse_dependencies(self.id) | ||
157 | .into_iter() | ||
158 | .map(|id| Crate { id }) | ||
159 | .collect() | ||
160 | } | ||
161 | |||
154 | pub fn root_module(self, db: &dyn HirDatabase) -> Module { | 162 | pub fn root_module(self, db: &dyn HirDatabase) -> Module { |
155 | let def_map = db.crate_def_map(self.id); | 163 | let def_map = db.crate_def_map(self.id); |
156 | Module { id: def_map.module_id(def_map.root()) } | 164 | Module { id: def_map.module_id(def_map.root()) } |
@@ -1497,11 +1505,17 @@ impl Impl { | |||
1497 | }; | 1505 | }; |
1498 | 1506 | ||
1499 | let mut all = Vec::new(); | 1507 | let mut all = Vec::new(); |
1500 | def_crates.into_iter().for_each(|id| { | 1508 | def_crates.iter().for_each(|&id| { |
1501 | all.extend(db.inherent_impls_in_crate(id).all_impls().map(Self::from).filter(filter)) | 1509 | all.extend(db.inherent_impls_in_crate(id).all_impls().map(Self::from).filter(filter)) |
1502 | }); | 1510 | }); |
1503 | let fp = TyFingerprint::for_impl(&ty.value); | 1511 | let fp = TyFingerprint::for_impl(&ty.value); |
1504 | for id in db.crate_graph().iter() { | 1512 | for id in def_crates |
1513 | .iter() | ||
1514 | .flat_map(|&id| Crate { id }.transitive_reverse_dependencies(db)) | ||
1515 | .map(|Crate { id }| id) | ||
1516 | .chain(def_crates.iter().copied()) | ||
1517 | .unique() | ||
1518 | { | ||
1505 | match fp { | 1519 | match fp { |
1506 | Some(fp) => all.extend( | 1520 | Some(fp) => all.extend( |
1507 | db.trait_impls_in_crate(id).for_self_ty(fp).map(Self::from).filter(filter), | 1521 | db.trait_impls_in_crate(id).for_self_ty(fp).map(Self::from).filter(filter), |
@@ -1516,7 +1530,8 @@ impl Impl { | |||
1516 | pub fn all_for_trait(db: &dyn HirDatabase, trait_: Trait) -> Vec<Impl> { | 1530 | pub fn all_for_trait(db: &dyn HirDatabase, trait_: Trait) -> Vec<Impl> { |
1517 | let krate = trait_.module(db).krate(); | 1531 | let krate = trait_.module(db).krate(); |
1518 | let mut all = Vec::new(); | 1532 | let mut all = Vec::new(); |
1519 | for Crate { id } in krate.reverse_dependencies(db).into_iter().chain(Some(krate)) { | 1533 | for Crate { id } in krate.transitive_reverse_dependencies(db).into_iter().chain(Some(krate)) |
1534 | { | ||
1520 | let impls = db.trait_impls_in_crate(id); | 1535 | let impls = db.trait_impls_in_crate(id); |
1521 | all.extend(impls.for_trait(trait_.id).map(Self::from)) | 1536 | all.extend(impls.for_trait(trait_.id).map(Self::from)) |
1522 | } | 1537 | } |