Fix unresolved-references DB attachment#22423
Closed
beardedeagle wants to merge 1 commit into
Closed
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a slow-test harness for the unresolved-references CLI and fixes a panic by correctly attaching the HIR database during analysis.
Changes:
- Introduces
Project::run_unresolved_references()to run the CLI against a fixture-built temp project. - Adds a slow test to ensure running on an empty crate does not panic.
- Wraps unresolved-reference scanning in
hir::attach_dbto avoid panics during HIR operations.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| crates/rust-analyzer/tests/slow-tests/support.rs | Adds a helper to materialize fixtures on disk and invoke the unresolved-references CLI. |
| crates/rust-analyzer/tests/slow-tests/cli.rs | Adds a regression test covering empty-crate behavior for unresolved references. |
| crates/rust-analyzer/src/cli/unresolved_references.rs | Attaches the HIR database while scanning modules to prevent panics. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| assert!(toolchain.is_none()); | ||
|
|
||
| for entry in fixture { | ||
| let path = tmp_dir.path().join(&entry.path['/'.len_utf8()..]); |
Comment on lines
+135
to
+145
| let FixtureWithProjectMeta { | ||
| fixture, | ||
| mini_core, | ||
| proc_macro_names, | ||
| toolchain, | ||
| target_data_layout: _, | ||
| target_arch: _, | ||
| } = FixtureWithProjectMeta::parse(self.fixture); | ||
| assert!(proc_macro_names.is_empty()); | ||
| assert!(mini_core.is_none()); | ||
| assert!(toolchain.is_none()); |
Comment on lines
+154
to
+161
| let root = self | ||
| .roots | ||
| .into_iter() | ||
| .map(|root| tmp_dir_path.join(root)) | ||
| .next() | ||
| .unwrap_or(tmp_dir_path); | ||
| flags::UnresolvedReferences { | ||
| path: root.into(), |
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.
Summary
Fixes a panic in the
rust-analyzer unresolved-referencesCLI command by attaching the HIR database while the command walks modules, classifies name references, and filters inactive-code diagnostics.The command currently panics before reporting results, even for an empty Cargo library crate:
analysis-statsalready wraps solver-heavy work inhir::attach_db(db, || ...); this applies the same pattern tounresolved-references.Test