diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-03-16 14:54:12 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-03-16 14:54:12 +0000 |
commit | 979e788957ced1957ee9ac1da70fb97abf9fe2b1 (patch) | |
tree | 1777ab043cb0750854b27a8aec805454de5c3277 /crates/hir/src | |
parent | b4ed3e1551f828d44dcd8e0caf08420438e5eb1a (diff) | |
parent | bebee2106de7bbd20f54d7f55d5c56dba0d636b6 (diff) |
Merge #8034
8034: Implement Crate::transitive_reverse_dependencies r=matklad a=Veykril
changelog internal Implement Crate::transitive_reverse_dependencies
Co-authored-by: Lukas Wirth <[email protected]>
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 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 | }; |
63 | use itertools::Itertools; | ||
63 | use rustc_hash::FxHashSet; | 64 | use rustc_hash::FxHashSet; |
64 | use stdx::{format_to, impl_from}; | 65 | use stdx::{format_to, impl_from}; |
65 | use syntax::{ | 66 | use 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 | } |