rust-lang / rust-lang/rust-analyzer
False E0608: cannot index into Vec<T, Global> in no_std project with custom target
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
rust-analyzer version: rust-analyzer 0.3.2929-standalone
rustc version: rustc 1.98.0-nightly (b30f3df3b 2026-06-11)
editor or extension: Neovim
relevant settings:
Project uses a custom no_std target through .cargo/config.toml:
[unstable]
json-target-spec = true
build-std-features = ["compiler-builtins-mem"]
build-std = ["core", "compiler_builtins", "alloc"]
[build]
target = "x86_64-eywuOS.json"
[target.'cfg(target_os = "none")']
runner = "./run.sh"
Custom target JSON:
{
"llvm-target": "x86_64-unknown-none",
"data-layout": "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128",
"arch": "x86_64",
"target-endian": "little",
"target-pointer-width": 64,
"target-c-int-width": 32,
"os": "none",
"executables": true,
"linker-flavor": "ld.lld",
"linker": "rust-lld",
"pre-link-args": {"ld.lld": ["-Tlinker.ld"]},
"panic-strategy": "abort",
"disable-redzone": true,
"features": "-mmx,-sse,+soft-float",
"rustc-abi": "x86-softfloat"
}
The crate is a no_std kernel using alloc and a custom global allocator. cargo check succeeds, but rust-analyzer reports a false E0608.
repository link (if public, optional): Not public.
code snippet to reproduce:
#![no_std]
#![no_main]
#![feature(abi_x86_interrupt)]
extern crate alloc;
use alloc::boxed::Box;
use alloc::vec::Vec;
use core::alloc::{GlobalAlloc, Layout};
use spin::Mutex;
const STACK_SIZE: usize = 4096;
#[derive(Debug, Clone, Copy)]
pub struct PhysAddr(pub u64);
#[allow(dead_code)]
#[derive(Debug)]
pub struct Task {
pub id: usize,
pub stack_pointer: u64,
pub page_table: PhysAddr,
pub kernel_stack_top: u64,
stack: Box<[u8; STACK_SIZE]>,
}
pub struct Scheduler {
pub tasks: Vec<Task>,
pub current: usize,
}
pub fn switch_task(scheduler: &mut Scheduler, next: usize) {
// rust-analyzer reports:
// E0608: cannot index into a value of type `Vec<Task, Global>`
//
// However, `cargo check` succeeds.
let next_rsp = scheduler.tasks[next].stack_pointer;
let next_pml4 = scheduler.tasks[next].page_table;
let next_kstack_top = scheduler.tasks[next].kernel_stack_top;
let _ = (next_rsp, next_pml4, next_kstack_top);
}
#[global_allocator]
static ALLOCATOR: LockedAllocator = LockedAllocator::new();
pub struct LockedAllocator(Mutex<LinkedListAllocator>);
impl LockedAllocator {
pub const fn new() -> Self {
Self(Mutex::new(LinkedListAllocator::new()))
}
}
pub struct LinkedListAllocator;
impl LinkedListAllocator {
pub const fn new() -> Self {
Self
}
unsafe fn alloc_inner(&mut self, _layout: Layout) -> *mut u8 {
core::ptr::null_mut()
}
unsafe fn add_free_block(&mut self, _addr: usize, _size: usize) {}
}
unsafe impl GlobalAlloc for LockedAllocator {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
unsafe { self.0.lock().alloc_inner(layout) }
}
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
unsafe {
self.0.lock().add_free_block(ptr as usize, layout.size());
}
}
}
cargo check succeeds for the real project and only emits unrelated warnings, but rust-analyzer inside neovim reports:
E0608: cannot index into a value of type `Vec<Task, Global>`
on valid indexing into alloc::vec::Vec<Task>.
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 diagnostic in Neovim using the project's .cargo/config.toml and custom x86_64-eywuOS.json target, focusing on the scheduler.tasks[next] indexing in switch_task. Compare rust-analyzer's result with the successful cargo check; done means valid Vec indexing no longer produces E0608 for this no_std custom-target setup.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- neovim, rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100