diff options
author | Florian Diebold <[email protected]> | 2020-02-21 20:49:02 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2020-02-22 10:09:21 +0000 |
commit | 2d5ab6324795e5fc36e4b61cb66737958dc67e7a (patch) | |
tree | 2027747769d99c7733ac4f4366ccffd4fcf4983f /crates/ra_hir_ty/src/utils.rs | |
parent | f126808b2ee79792631edc377bc8c2b0f329eebf (diff) |
Add &dyn Trait -> &dyn SuperTrait coercion, and fix &T -> &dyn Trait
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, |