diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-03-15 14:08:26 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-03-15 14:08:26 +0000 |
commit | f2c39d0cdf708d6178740385f58d6b2b657e411a (patch) | |
tree | 83ed009ee98b3c1cfe1cbcc203c1c419c914569e /crates/hir_ty | |
parent | 3962b0d53c8da6e3f95f54395d266cb99562bd47 (diff) | |
parent | 79561b9d2e901e2624f94ffa7bc6017f0249f23d (diff) |
Merge #8020
8020: Power up goto_implementation r=matklad a=Veykril
by allowing it to be invoked on references of names, now showing all (trait)
implementations of the given type in all crates instead of just the defining
crate as well as including support for builtin types
![image](https://user-images.githubusercontent.com/3757771/111144403-52bb0700-8587-11eb-9205-7a2a5b8b75a3.png)
Example screenshot of `impl`s of Box in `log`, `alloc`, `std` and the current crate. Before you had to invoke it on the definition where it would only show the `impls` in `alloc`.
Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/hir_ty')
-rw-r--r-- | crates/hir_ty/src/method_resolution.rs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/crates/hir_ty/src/method_resolution.rs b/crates/hir_ty/src/method_resolution.rs index 741440006..be72c4a1c 100644 --- a/crates/hir_ty/src/method_resolution.rs +++ b/crates/hir_ty/src/method_resolution.rs | |||
@@ -44,7 +44,7 @@ impl TyFingerprint { | |||
44 | /// Creates a TyFingerprint for looking up an impl. Only certain types can | 44 | /// Creates a TyFingerprint for looking up an impl. Only certain types can |
45 | /// have impls: if we have some `struct S`, we can have an `impl S`, but not | 45 | /// have impls: if we have some `struct S`, we can have an `impl S`, but not |
46 | /// `impl &S`. Hence, this will return `None` for reference types and such. | 46 | /// `impl &S`. Hence, this will return `None` for reference types and such. |
47 | pub(crate) fn for_impl(ty: &Ty) -> Option<TyFingerprint> { | 47 | pub fn for_impl(ty: &Ty) -> Option<TyFingerprint> { |
48 | let fp = match *ty.interned(&Interner) { | 48 | let fp = match *ty.interned(&Interner) { |
49 | TyKind::Str => TyFingerprint::Str, | 49 | TyKind::Str => TyFingerprint::Str, |
50 | TyKind::Never => TyFingerprint::Never, | 50 | TyKind::Never => TyFingerprint::Never, |
@@ -141,6 +141,14 @@ impl TraitImpls { | |||
141 | } | 141 | } |
142 | } | 142 | } |
143 | 143 | ||
144 | /// Queries all trait impls for the given type. | ||
145 | pub fn for_self_ty(&self, fp: TyFingerprint) -> impl Iterator<Item = ImplId> + '_ { | ||
146 | self.map | ||
147 | .values() | ||
148 | .flat_map(move |impls| impls.get(&None).into_iter().chain(impls.get(&Some(fp)))) | ||
149 | .flat_map(|it| it.iter().copied()) | ||
150 | } | ||
151 | |||
144 | /// Queries all impls of the given trait. | 152 | /// Queries all impls of the given trait. |
145 | pub fn for_trait(&self, trait_: TraitId) -> impl Iterator<Item = ImplId> + '_ { | 153 | pub fn for_trait(&self, trait_: TraitId) -> impl Iterator<Item = ImplId> + '_ { |
146 | self.map | 154 | self.map |