rust-lang / rust-lang/rust-analyzer
Panic when crate graph is empty
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
I can reliably make rust-analyzer panic index out of bounds: the len is 0 but the index is 0 when there's no crate graph loaded.
This typically occurs when there's a discover command configured which doesn't support the current directory, but I imagine you'd hit it when you have a standalone Rust file too.
The indexing error is here:
So e.g. when you type 1. without a crate graph, r-a panics when it tries to access the crate of i32:
This feels like the API is the wrong shape, and we shouldn't assume that all types have an associated type (I see HasCrate is implemented for Type).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the panic with an empty crate graph while typing 1., then inspect the indexing at crates/hir/src/lib.rs#L4471-L4474 and the callers in crates/ide-completion/src/context/analysis.rs#L1016 and crates/hir/src/lib.rs#L2406. Trace the HasCrate assumption for Type and add a regression test demonstrating the empty-graph case. Done means the scenario no longer panics.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100