Skip to content

Fix unresolved-references DB attachment#22423

Closed
beardedeagle wants to merge 1 commit into
rust-lang:masterfrom
beardedeagle:fix-unresolved-references-db-attach
Closed

Fix unresolved-references DB attachment#22423
beardedeagle wants to merge 1 commit into
rust-lang:masterfrom
beardedeagle:fix-unresolved-references-db-attach

Conversation

@beardedeagle
Copy link
Copy Markdown

Summary

Fixes a panic in the rust-analyzer unresolved-references CLI 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:

thread 'BIG_STACK_THREAD' panicked at crates/hir-ty/src/next_solver/interner.rs:2440:42:
Try to use attached db, but not db is attached

analysis-stats already wraps solver-heavy work in hir::attach_db(db, || ...); this applies the same pattern to unresolved-references.

Test

RUN_SLOW_TESTS=1 cargo test -p rust-analyzer --test slow-tests unresolved_references_empty_crate_does_not_panic -- --nocapture
cargo fmt --check

Copilot AI review requested due to automatic review settings May 23, 2026 02:28
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 23, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_db to 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.

View changes since this review

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(),
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 23, 2026
@beardedeagle beardedeagle deleted the fix-unresolved-references-db-attach branch May 23, 2026 02:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants