From 6241567948b644739d2ae904e74f5f10cd5b2bb6 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 15 Mar 2021 13:49:21 +0100 Subject: Speedup trait impl search for goto_implementation --- crates/hir/src/lib.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'crates/hir') diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index a9d3c9156..42a805c57 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -51,7 +51,8 @@ use hir_expand::{diagnostics::DiagnosticSink, name::name, MacroDefKind}; use hir_ty::{ autoderef, display::{write_bounds_like_dyn_trait_with_prefix, HirDisplayError, HirFormatter}, - method_resolution, to_assoc_type_id, + method_resolution::{self, TyFingerprint}, + to_assoc_type_id, traits::{FnTrait, Solution, SolutionVariables}, AliasTy, BoundVar, CallableDefId, CallableSig, Canonical, DebruijnIndex, GenericPredicate, InEnvironment, Interner, Obligation, ProjectionPredicate, ProjectionTy, Scalar, Substs, Ty, @@ -1500,13 +1501,20 @@ impl Impl { def_crates.iter().for_each(|&id| { all.extend(db.inherent_impls_in_crate(id).all_impls().map(Self::from).filter(filter)) }); + let fp = TyFingerprint::for_impl(&ty.value); for id in def_crates .iter() .flat_map(|&id| Crate { id }.reverse_dependencies(db)) .map(|Crate { id }| id) .chain(def_crates.iter().copied()) { - all.extend(db.trait_impls_in_crate(id).all_impls().map(Self::from).filter(filter)); + match fp { + Some(fp) => all.extend( + db.trait_impls_in_crate(id).for_self_ty(fp).map(Self::from).filter(filter), + ), + None => all + .extend(db.trait_impls_in_crate(id).all_impls().map(Self::from).filter(filter)), + } } all } -- cgit v1.2.3