rust-lang/rust-analyzer · error
you have way too many items in the same file!
Error message
you have way too many items in the same file!
What it means
AstIdMap uses an open-addressed hash table to assign compact ids (ErasedFileAstId) to syntax nodes of a single file, encoding hash, index, and kind into one u32. When probing for a free slot wraps all the way around to the initial hash, it means 2^27 (134,217,728) items were hashed into the same file's map — the id space is exhausted. This is an intentional safeguard against runaway insertion, since a real source file can never legitimately contain that many items.
Source
Thrown at crates/span/src/ast_id.rs:491
let mut hash = initial_hash;
let index = loop {
match self.0.entry((kind, hash)) {
std::collections::hash_map::Entry::Occupied(mut entry) => {
let i = entry.get_mut();
if *i < ((1 << INDEX_BITS) - 1) {
*i += 1;
break *i;
}
}
std::collections::hash_map::Entry::Vacant(entry) => {
entry.insert(0);
break 0;
}
}
hash = hash.wrapping_add(1);
if hash == initial_hash {
// That's 2^27=134,217,728 items!
panic!("you have way too many items in the same file!");
}
};
let kind = kind as u32;
ErasedFileAstId(pack_hash_index_and_kind(hash, index, kind))
}
}
macro_rules! register_enum_ast_id {
(impl $AstIdNode:ident for $($ident:ident),+ ) => {
$(
impl $AstIdNode for ast::$ident {}
)+
};
}
register_enum_ast_id! {
impl AstIdNode for
Item, AnyHasGenericParams, Adt, Macro,
AssocItemView on GitHub (pinned to e8f7e90aa3)
Solutions
- Reduce the number of items inserted into a single file's AstIdMap (split or truncate the file)
- If you changed AstIdMap internals, verify the probe loop terminates correctly and capacity invariants hold
- Check for a bug that re-inserts the same nodes infinitely (arena growth loop)
Defensive patterns
Strategy: validation
Validate before calling
// Cap file size before parsing/id-mapping:
if node_count_estimate(file_text) > MAX_SUPPORTED_ITEMS {
return Err(AnalysisCancelled::FileTooLarge);
} Try / catch
// Wrap map construction during experiments:
let map = std::panic::catch_unwind(|| AstIdMap::from_source(source))
.unwrap_or_else(|_| AstIdMap::default()); Prevention
- Don't feed synthetic multi-hundred-million-node files to analysis
- Review probe-loop/termination logic when touching AstIdMap internals
- Fuzz AstIdMap with large generated inputs before landing encoding changes
When it happens
Trigger: Inserting more than 2^27 distinct AST nodes into a single AstIdMap via `new_id`, which in practice only happens if the insertion loop never finds its slot due to a corrupted/oversized map, or a pathological generated/huge file, or a bug inserting the same overflowing data repeatedly.
Common situations: Essentially only seen by rust-analyzer developers during changes to AstIdMap internals (hashing, capacity, or arena growth), or when fuzzing/parsing an absurdly large synthetic file; end users should never hit it.
Related errors
- AstIdMap node mismatch with node `{ptr:?}`
- We explicitly do not provide canonicalization API, as that i
- bad kind {other}
- bad spacing {other}
- bad tag: {other}
AI-assisted analysis of rust-lang/rust-analyzer@e8f7e90aa3 (2026-09-03).
Data as JSON: /api/errors/fe7c2fdf7eeab976.
Report an issue: GitHub.