rust-lang / rust-lang/rust-analyzer

When building with `no_std`, `alloc` imports don't also add `extern crate alloc`

Open
#12,978 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-completion A-no_std C-feature
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

When working on a #![no_std] crate and doing a code complete on Vec, selecting alloc::vec::Vec, the import is added to the top of the file, but an appropriate extern crate alloc; is not added anywhere, causing the project to immediately complain and fail to build.

It would be better if RA could detect this and add the extern crate at the crate root.

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

The issue concerns completion and import insertion for alloc::vec::Vec in a #![no_std] crate; start by tracing that completion path and its handling of crate-root imports. Done means selecting the item adds both the import and extern crate alloc without regressing normal std cases; add focused coverage in the relevant test area.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
developer-experience, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.