aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/method_resolution.rs
diff options
context:
space:
mode:
authorLukas Wirth <[email protected]>2021-03-15 12:49:21 +0000
committerLukas Wirth <[email protected]>2021-03-15 12:49:21 +0000
commit6241567948b644739d2ae904e74f5f10cd5b2bb6 (patch)
tree7af5ca0990c536409ea1e2044f0fc5aa63a3702d /crates/hir_ty/src/method_resolution.rs
parent6c782a53148dc2f34be2eafbdf872ab6497632fd (diff)
Speedup trait impl search for goto_implementation
Diffstat (limited to 'crates/hir_ty/src/method_resolution.rs')
-rw-r--r--crates/hir_ty/src/method_resolution.rs10
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 c7055bee5..57f37ef4b 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