diff options
author | Florian Diebold <[email protected]> | 2019-09-07 15:24:26 +0100 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2019-09-07 15:30:31 +0100 |
commit | a1776b27c7d7c266d751360b80cc573b1520ef65 (patch) | |
tree | 743356958f4968ae08f5891f10a09bfbc6eb6443 /crates/ra_hir/src/ty/traits.rs | |
parent | d21cdf3c998bb24e48e81a7e6909df2146ce097c (diff) |
Use traits from where clauses for method resolution
E.g. if we have `T: some::Trait`, we can call methods from that trait without it
needing to be in scope.
Diffstat (limited to 'crates/ra_hir/src/ty/traits.rs')
-rw-r--r-- | crates/ra_hir/src/ty/traits.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/crates/ra_hir/src/ty/traits.rs b/crates/ra_hir/src/ty/traits.rs index 6e0271a96..c0c132809 100644 --- a/crates/ra_hir/src/ty/traits.rs +++ b/crates/ra_hir/src/ty/traits.rs | |||
@@ -96,6 +96,21 @@ pub struct TraitEnvironment { | |||
96 | pub predicates: Vec<GenericPredicate>, | 96 | pub predicates: Vec<GenericPredicate>, |
97 | } | 97 | } |
98 | 98 | ||
99 | impl TraitEnvironment { | ||
100 | /// Returns trait refs with the given self type which are supposed to hold | ||
101 | /// in this trait env. E.g. if we are in `foo<T: SomeTrait>()`, this will | ||
102 | /// find that `T: SomeTrait` if we call it for `T`. | ||
103 | pub(crate) fn trait_predicates_for_self_ty<'a>( | ||
104 | &'a self, | ||
105 | ty: &'a Ty, | ||
106 | ) -> impl Iterator<Item = &'a TraitRef> + 'a { | ||
107 | self.predicates.iter().filter_map(move |pred| match pred { | ||
108 | GenericPredicate::Implemented(tr) if tr.self_ty() == ty => Some(tr), | ||
109 | _ => None, | ||
110 | }) | ||
111 | } | ||
112 | } | ||
113 | |||
99 | /// Something (usually a goal), along with an environment. | 114 | /// Something (usually a goal), along with an environment. |
100 | #[derive(Clone, Debug, PartialEq, Eq, Hash)] | 115 | #[derive(Clone, Debug, PartialEq, Eq, Hash)] |
101 | pub struct InEnvironment<T> { | 116 | pub struct InEnvironment<T> { |