internal: Migrate HirDatabase away from #[query_group]; remove the latter#22831
Open
ada4a wants to merge 5 commits into
Open
internal: Migrate HirDatabase away from #[query_group]; remove the latter#22831ada4a wants to merge 5 commits into
HirDatabase away from #[query_group]; remove the latter#22831ada4a wants to merge 5 commits into
Conversation
- 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`).
HirDatabase away from #[query_group]; remove the latterHirDatabase away from #[query_group]; remove the latter
ada4a
marked this pull request as ready for review
July 16, 2026 08:17
ChayimFriedman2
requested changes
Jul 17, 2026
Contributor
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #22657 🎉
See #t-compiler/rust-analyzer > Migrating `HirDatabase` for discussion, and individual commits for details.