Skip to content

Commit 0558cc4

Browse files
committed
Add method Impl::all_in_module(…) for allowing more localized querying
1 parent cf156a7 commit 0558cc4

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

crates/hir/src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3701,6 +3701,24 @@ impl Impl {
37013701
inherent.all_impls().chain(trait_.all_impls()).map(Self::from).collect()
37023702
}
37033703

3704+
pub fn all_in_module(db: &dyn HirDatabase, module: Module) -> Vec<Impl> {
3705+
if let Some(block_id) = module.id.containing_block() {
3706+
let mut impls = vec![];
3707+
3708+
if let Some(inherent_impls) = db.inherent_impls_in_block(block_id) {
3709+
impls.extend(inherent_impls.all_impls().into_iter().map(Self::from));
3710+
}
3711+
3712+
if let Some(trait_impls) = db.trait_impls_in_block(block_id) {
3713+
impls.extend(trait_impls.all_impls().into_iter().map(Self::from));
3714+
}
3715+
3716+
impls
3717+
} else {
3718+
Self::all_in_crate(db, module.krate())
3719+
}
3720+
}
3721+
37043722
pub fn all_for_type(db: &dyn HirDatabase, Type { ty, env }: Type) -> Vec<Impl> {
37053723
let def_crates = match method_resolution::def_crates(db, &ty, env.krate) {
37063724
Some(def_crates) => def_crates,

0 commit comments

Comments
 (0)