Skip to content

internal: Migrate HirDatabase away from #[query_group]; remove the latter#22831

Open
ada4a wants to merge 5 commits into
rust-lang:masterfrom
ada4a:unquerygroup-hirdatabase
Open

internal: Migrate HirDatabase away from #[query_group]; remove the latter#22831
ada4a wants to merge 5 commits into
rust-lang:masterfrom
ada4a:unquerygroup-hirdatabase

Conversation

@ada4a

@ada4a ada4a commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Resolves #22657 🎉

See #t-compiler/rust-analyzer > Migrating `HirDatabase` for discussion, and individual commits for details.

ada4a added 5 commits July 15, 2026 21:28
- don't `push_ty_diagnostics` with an empty list
- use `lookup_resolver`
The next commit would require us to `impl HirDatabase for dyn
SourceDatabase + Debug`, but that wouldn't work, as trait objects can't
specify multiple (non-auto) traits. Since we're going to change all the
users of `dyn HirDatabase` to `dyn SourceDatabase` anyway, we can push
the `Debug` bound down to the latter.
The remaining methods in the query group didn't really have a good place
to migrate them to, as they were all defined on `hir-def` types.
Therefore, we basically left them inside `HirDatabase`, but changed the
latter from a `#[query_group]` to an extension trait on
`SourceDatabase`.

This means that, in order to use its queries, one needs to bring it into
scope. In particular, when working with a concrete
`TestDB`/`RootDatabase`, one needs to first explicitly cast it to a
`&dyn SourceDatabase`, so that the compiler can then cast it to `&dyn
HirDatabase` as needed. In this commit, I do so as late as possible, to
avoid changing too much code (notably, &`db` to `db`).
@ada4a ada4a changed the title Migrate HirDatabase away from #[query_group]; remove the latter internal: Migrate HirDatabase away from #[query_group]; remove the latter Jul 16, 2026
@ada4a
ada4a marked this pull request as ready for review July 16, 2026 08:17
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 16, 2026

@ChayimFriedman2 ChayimFriedman2 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the many places that need to explicitly coerce to &dyn SourceDatabase. I think a better solution is to add fn as_dyn(&self) -> &dyn SourceDatabase to RootDatabase and TestDB. Maybe even implement Deref, although that's probably a bad idea.

View changes since this review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

3 participants