rust-lang / rust-lang/rust-analyzer

auto-import on `alloc::vec` macro instead imports `alloc::vec::{Self}` module

Open
#11,278 4 comments 8 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-assists C-bug S-actionable
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.