Rust-analyzer no_std unresolved crate alloc
⚓ Rust 📅 2026-02-26 👤 surdeus 👁️ 2I am working on a bare-metal project. When I add extern crate alloc, rust-analyzer reports an error (unresolved extern crate). When I goto-defintion on alloc, that works and the error disappears until I restart rust-analyzer. cargo check runs without any complaints (cargo check --target x86_64-unknown-none -Zbuild-std=core,alloc -Zbuild-std-features=compiler-builtins-mem). I am unsure if this is a rust-analyzer bug or if I am just configuring it wrong.
Cargo.toml
[package]
name = "rust-analyzer-demo"
version = "0.1.0"
edition = "2024"
[[bin]]
name = "rust-analyzer-demo"
path = "src/main.rs"
test = false
doctest = false
bench = false
[dependencies]
main.rs
#![no_main]
#![no_std]
extern crate alloc;
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo<'_>) -> ! {
loop {}
}
use core::alloc::GlobalAlloc;
struct Ga;
#[global_allocator]
static GA: Ga = Ga;
unsafe impl GlobalAlloc for Ga {
unsafe fn alloc(&self, _layout: core::alloc::Layout) -> *mut u8 {
todo!()
}
unsafe fn dealloc(&self, _ptr: *mut u8, _layout: core::alloc::Layout) {
todo!()
}
}
.helix/languages.toml
[language-server.rust-analyzer.config.cargo]
extraArgs = [
"-Zbuild-std=core,alloc",
"-Zbuild-std-features=compiler-builtins-mem",
]
target = "x86_64-unknown-none"
[language-server.rust-analyzer.config.check]
extraArgs = [
"-Zbuild-std=core,alloc",
"-Zbuild-std-features=compiler-builtins-mem",
]
targets = [
"x86_64-unknown-none",
]
1 post - 1 participant
🏷️ Rust_feed