rust-lang / rust-lang/rust-analyzer
When adding an import based on a completion to a unit test it becomes an unused import in the normal build
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
The problem is that if you have some code like
#[test]
fn test_all_room_ids_different() {
let mut set = HashS
}
and then you press Ctrl+Space at the end of the line and pick std::collections::HashSet as the completion, it'll add the std::collections::HashSet to the top of the entire module. Except if nothing else in the module is using a HashSet then the non-test build now marks the import as an unused import.
I don't know what the good answer is here, but there are two options that come to mind:
- put the new import at the top of the test function
- put the new import at the top of the module behind
#[cfg(test)]
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
Reproduce the completion-import behavior in a Rust unit test where HashSet is used only inside #[test]. Then inspect the completion import insertion entry point and determine whether the import should be scoped to the test or guarded with #[cfg(test)]. Done means the normal build no longer reports the generated import as unused.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100