Skip to content

Commit 20c6698

Browse files
committed
Auto merge of rust-lang#17610 - regexident:impl-all_in_module, r=Veykril
Add method `Impl::all_in_module(…)` for allowing more localized querying This PR is motivated by an [outside use](https://github.com/regexident/cargo-modules) of the `ra_ap_hir` crate that would benefit from being able to more efficiently query for all impls of a given module (instead of having to query for its parent crate's impls and then filtering on `impl_hir.module(db) == module_hir`). I have the suspicion that the code as is won't quite work for file-level modules, since those don't have a block, afaict, but with all the crate-rename and version shenanigans around the `ra_ap_` release process I haven't yet been able to figure out how to patch a `ra_ap_` dependency from a third-party crate (let alone how to test this from inside of `rust-analyzer`), so haven't been able to actually run and test this. 😔 Any hints on how to make this (i.e. the code itself, as well as the testing) work are more than welcome!
2 parents dbdf992 + 0cbee3b commit 20c6698

File tree

1 file changed

+4
-0
lines changed
  • src/tools/rust-analyzer/crates/hir/src

1 file changed

+4
-0
lines changed

src/tools/rust-analyzer/crates/hir/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3724,6 +3724,10 @@ impl Impl {
37243724
inherent.all_impls().chain(trait_.all_impls()).map(Self::from).collect()
37253725
}
37263726

3727+
pub fn all_in_module(db: &dyn HirDatabase, module: Module) -> Vec<Impl> {
3728+
module.id.def_map(db.upcast())[module.id.local_id].scope.impls().map(Into::into).collect()
3729+
}
3730+
37273731
pub fn all_for_type(db: &dyn HirDatabase, Type { ty, env }: Type) -> Vec<Impl> {
37283732
let def_crates = match method_resolution::def_crates(db, &ty, env.krate) {
37293733
Some(def_crates) => def_crates,

0 commit comments

Comments
 (0)