rust-lang / rust-lang/rust-analyzer
auto-import on `alloc::vec` macro instead imports `alloc::vec::{Self}` module
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
If I start a new library, with this code:
#![no_std]
extern crate alloc;
pub fn foo() -> Vec<u32> {
vec![]
}
I get two unresolved symbols, Vec and vec. If I allow rust-analyzer to import those symbols, I first select "import `alloc::vec::Vec`", and then "import `alloc::vec`". This results in the added line:
use alloc::vec::{Vec, self};
This doesn't work (code will not compile), because self refers to the module alloc::vec, and this code needs the macro alloc::vec.
rust-analyzer version: 0add6e95e 2021-12-20 stable
rustc version: 1.58.0
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 issue with the provided no_std library and alloc::vec example using the stated rust-analyzer and rustc versions. Trace the auto-import handling for alloc::vec::Vec and the vec macro, paying attention to the distinction between the module and macro. Done means the suggested imports produce compiling Rust code and the regression is covered by an appropriate test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100