|
4 | 4 | //! and the corresponding code mostly in rustc_hir_analysis/check/method/probe.rs. |
5 | 5 | use std::ops::ControlFlow; |
6 | 6 |
|
| 7 | +use arrayvec::ArrayVec; |
7 | 8 | use base_db::CrateId; |
8 | 9 | use chalk_ir::{cast::Cast, UniverseIndex, WithKind}; |
9 | 10 | use hir_def::{ |
@@ -732,15 +733,27 @@ fn lookup_impl_assoc_item_for_trait_ref( |
732 | 733 | let self_ty = trait_ref.self_type_parameter(Interner); |
733 | 734 | let self_ty_fp = TyFingerprint::for_trait_impl(&self_ty)?; |
734 | 735 | let impls = db.trait_impls_in_deps(env.krate); |
735 | | - let self_impls = match self_ty.kind(Interner) { |
736 | | - TyKind::Adt(id, _) => { |
737 | | - id.0.module(db.upcast()).containing_block().and_then(|it| db.trait_impls_in_block(it)) |
| 736 | + |
| 737 | + let trait_module = hir_trait_id.module(db.upcast()); |
| 738 | + let type_module = match self_ty_fp { |
| 739 | + TyFingerprint::Adt(adt_id) => Some(adt_id.module(db.upcast())), |
| 740 | + TyFingerprint::ForeignType(type_id) => { |
| 741 | + Some(from_foreign_def_id(type_id).module(db.upcast())) |
738 | 742 | } |
| 743 | + TyFingerprint::Dyn(trait_id) => Some(trait_id.module(db.upcast())), |
739 | 744 | _ => None, |
740 | 745 | }; |
| 746 | + |
| 747 | + let def_blocks: ArrayVec<_, 2> = |
| 748 | + [trait_module.containing_block(), type_module.and_then(|it| it.containing_block())] |
| 749 | + .into_iter() |
| 750 | + .flatten() |
| 751 | + .filter_map(|block_id| db.trait_impls_in_block(block_id)) |
| 752 | + .collect(); |
| 753 | + |
741 | 754 | let impls = impls |
742 | 755 | .iter() |
743 | | - .chain(self_impls.as_ref()) |
| 756 | + .chain(&def_blocks) |
744 | 757 | .flat_map(|impls| impls.for_trait_and_self_ty(hir_trait_id, self_ty_fp)); |
745 | 758 |
|
746 | 759 | let table = InferenceTable::new(db, env); |
|
0 commit comments