{"id":"0bd50ddeb527865a","repo":"rust-lang/rust","slug":"incremental-cache-file-size-overflowed-u64","errorCode":null,"errorMessage":"Incremental cache file size overflowed u64.","messagePattern":"Incremental cache file size overflowed u64\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"compiler/rustc_middle/src/query/on_disk_cache.rs","lineNumber":122,"sourceCode":"    // without measurable overhead. This permits larger const allocations without ICEing.\n    interpret_alloc_index: Vec<u64>,\n    // See `OnDiskCache.syntax_contexts`\n    syntax_contexts: FxHashMap<u32, AbsoluteBytePos>,\n    // See `OnDiskCache.expn_data`\n    expn_data: UnhashMap<ExpnHash, AbsoluteBytePos>,\n    foreign_expn_data: UnhashMap<ExpnHash, u32>,\n}\n\n#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, Encodable, Decodable)]\nstruct SourceFileIndex(u32);\n\n#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, Encodable, Decodable)]\npub struct AbsoluteBytePos(u64);\n\nimpl AbsoluteBytePos {\n    #[inline]\n    pub fn new(pos: usize) -> AbsoluteBytePos {\n        AbsoluteBytePos(pos.try_into().expect(\"Incremental cache file size overflowed u64.\"))\n    }\n\n    #[inline]\n    fn to_usize(self) -> usize {\n        self.0 as usize\n    }\n}\n\n#[derive(Encodable, Decodable, Clone, Debug)]\nstruct EncodedSourceFileId {\n    stable_source_file_id: StableSourceFileId,\n    stable_crate_id: StableCrateId,\n}\n\nimpl EncodedSourceFileId {\n    #[inline]\n    fn new(tcx: TyCtxt<'_>, file: &SourceFile) -> EncodedSourceFileId {\n        EncodedSourceFileId {","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_middle/src/query/on_disk_cache.rs#L104-L140","documentation":"`AbsoluteBytePos::new` (on_disk_cache.rs:122) converts a `usize` byte offset into the on-disk incremental cache into a `u64` via `try_into().expect(...)`. The conversion only fails for offsets beyond 2^64 bytes (≈16 EiB), which is physically unreachable for any real file. The panic exists as a defensive guard against corrupted length math upstream, not as a realistic capacity limit.","triggerScenarios":"Reached only if some encoder computes a byte position whose `usize` value exceeds `u64::MAX`—impossible for legitimate files but theoretically reachable if a length field is read from a corrupted/truncated cache file and interpreted as an enormous offset, or if an internal arithmetic bug produces a wraparound value that happens to land above `u64::MAX` on a platform where `usize` is 128-bit (none exist today).","commonSituations":"Practically never seen in the wild. The realistic path is a corrupted incremental-cache file (disk error, NFS oddity, interrupted write) feeding garbage offsets into the encoder, or a hypothetical future 128-bit `usize` platform with a buggy length computation. Normal users should treat any sighting as cache corruption.","solutions":["Delete the incremental cache and rebuild: `cargo clean && cargo build`.","Inspect the failing crate's `target/<triple>/incremental/` for the corrupted `.rlib`/cache file and remove just that file.","Disable incremental compilation: `CARGO_INCREMENTAL=0`.","Check disk health / free space and ensure no process is truncating `target/` mid-build.","Report to rust-lang/rust if it persists after a clean build, attaching `rustc -vV`."],"exampleFix":"# before\n$ cargo build   # panic: Incremental cache file size overflowed u64.\n\n# after\n$ rm -rf target/<triple>/incremental\n$ cargo build   # rebuilds the cache from scratch","handlingStrategy":"validation","validationCode":"// Validate that the on-disk incremental cache has not grown pathologically large\n// before invoking cargo, so the u64-size overflow cannot be hit.\nuse std::path::Path;\nfn incremental_cache_size_ok(target_dir: &Path, limit_bytes: u64) -> bool {\n    let Some(target) = target_dir.canonicalize().ok() else { return true; };\n    let inc = target.join(\"debug\").join(\"incremental\");\n    if !inc.exists() { return true; }\n    let mut total: u64 = 0;\n    let mut stack = vec![inc];\n    while let Some(dir) = stack.pop() {\n        let Ok(rd) = std::fs::read_dir(&dir) else { continue };\n        for entry in rd.flatten() {\n            let p = entry.path();\n            if p.is_dir() { stack.push(p); }\n            else if let Ok(m) = entry.metadata() { total = total.saturating_add(m.len()); }\n        }\n    }\n    total < limit_bytes // e.g. 4 GiB ceiling; prune if exceeded\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Periodically `cargo clean` or prune `target/<profile>/incremental/`.","Disable incremental in long-lived build dirs (`CARGO_INCREMENTAL=0`).","Monitor free disk space; an overflowing cache often correlates with a nearly-full volume.","Avoid symlinking `target/` onto filesystems with unusual max-file-size limits."],"tags":["rustc","incremental-compilation","on-disk-cache","cache-corruption","internal-compiler-error"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}