diff options
Diffstat (limited to 'crates/ra_hir_ty/src/utils.rs')
-rw-r--r-- | crates/ra_hir_ty/src/utils.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/crates/ra_hir_ty/src/utils.rs b/crates/ra_hir_ty/src/utils.rs index 508ae9046..0d1583c39 100644 --- a/crates/ra_hir_ty/src/utils.rs +++ b/crates/ra_hir_ty/src/utils.rs | |||
@@ -62,6 +62,27 @@ pub(super) fn all_super_traits(db: &impl DefDatabase, trait_: TraitId) -> Vec<Tr | |||
62 | result | 62 | result |
63 | } | 63 | } |
64 | 64 | ||
65 | /// Finds a path from a trait to one of its descendant traits. Returns an empty | ||
66 | /// vector if there is no path. | ||
67 | pub(super) fn find_super_trait_path( | ||
68 | db: &impl DefDatabase, | ||
69 | super_trait: TraitId, | ||
70 | trait_: TraitId, | ||
71 | ) -> Vec<TraitId> { | ||
72 | if trait_ == super_trait { | ||
73 | return vec![trait_]; | ||
74 | } | ||
75 | |||
76 | for tt in direct_super_traits(db, trait_) { | ||
77 | let mut path = find_super_trait_path(db, super_trait, tt); | ||
78 | if !path.is_empty() { | ||
79 | path.push(trait_); | ||
80 | return path; | ||
81 | } | ||
82 | } | ||
83 | Vec::new() | ||
84 | } | ||
85 | |||
65 | pub(super) fn associated_type_by_name_including_super_traits( | 86 | pub(super) fn associated_type_by_name_including_super_traits( |
66 | db: &impl DefDatabase, | 87 | db: &impl DefDatabase, |
67 | trait_: TraitId, | 88 | trait_: TraitId, |