rust-lang/rust · error · io::Error
{context}: {err}
Error message
{context}: {err} What it means
This is the io_error_context helper function (archive.rs:720-722), not a standalone error. It wraps any std::io::Error with a context prefix string and is used throughout ArArchiveBuilder::build_inner for operations including opening object files, memory-mapping, creating temp directories, creating temp files, renaming the final archive, flushing, and removing temp dirs. The {context} identifies which step failed; {err} carries the OS-level error message.
Solutions
- Read the {context} prefix to identify which operation failed, then address the {err} cause directly.
- For permission errors: ensure the output directory and all intermediate paths are writable by the build user.
- For 'failed to map object file': check available memory and virtual address space; on Linux check /proc/sys/vm/max_map_count.
- For temp file/rename errors: ensure the output path is on the same filesystem as the system temp dir, or set TMPDIR to a location on the same volume.
- For disk-full: free space or redirect the build output to a larger volume.
Example fix
# before: temp dir on a different filesystem than output, causing rename failure TMPDIR=/tmp cargo build --release # output on /data, rename fails cross-device # after: set TMPDIR on the same filesystem as the output TMPDIR=/data/tmp cargo build --release
Defensive patterns
Strategy: try-catch
Validate before calling
// Before building, verify the output directory is writable and has space.
use std::path::Path;
fn verify_output_dir(path: &Path) -> Result<(), String> {
fs::create_dir_all(path).map_err(|e| format!("cannot create output dir {}: {}", path.display(), e))?;
let test_file = path.join(".write_test");
std::fs::write(&test_file, b"test").map_err(|e| format!("output dir not writable: {}", e))?;
std::fs::remove_file(&test_file).ok();
Ok(())
} Try / catch
// io_error_context wraps io::Error; errors from build_inner propagate as
// ArchiveBuildFailure fatal diagnostic. Guard at the build-system level:
// ensure TMPDIR and the output directory are on the same filesystem.
// In build scripts:
if let Err(e) = std::fs::create_dir_all(&output_dir) {
eprintln!("cannot prepare output directory: {e}");
std::process::exit(1);
} Prevention
- Ensure TMPDIR is on the same filesystem as the build output to avoid cross-device rename failures.
- Check ulimit -n (open file descriptors) for large builds.
- Verify write permissions on the output directory before starting a build.
- Monitor disk space — archive building is write-intensive.
When it happens
Trigger: Any IO failure during archive building: 'failed to open object file' (permission denied or missing file), 'failed to map object file' (mmap failure), 'couldn't create a directory for the temp file' (disk full or permission denied on output dir), 'couldn't create the temp file', 'failed to rename archive file' (cross-device rename or target exists), 'failed to remove temporary directory'.
Common situations: Output directory is read-only or doesn't exist; disk full during archive write; insufficient file descriptors (ulimit); antivirus or file watcher locking temp files on Windows; NFS/network filesystem mmap issues; running out of inodes.
Related errors
- archive member at offset
- cannot allocate registers
- erroneous constant missed by mono item collection
- expected monomorphic const in codegen
- expected monomorphic const in codegen
AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10).
Data as JSON: /api/errors/2e647dcd56b71679.
Report an issue: GitHub.
Appendix: source
Thrown at compiler/rustc_codegen_ssa/src/back/archive.rs:721
let any_entries = !entries.is_empty();
drop(entries);
// Drop src_archives to unmap all input archives, which is necessary if we want to write the
// output archive to the same location as an input archive on Windows.
drop(self.src_archives);
fs::rename(archive_tmpfile_path, output)
.map_err(|err| io_error_context("failed to rename archive file", err))?;
archive_tmpdir
.close()
.map_err(|err| io_error_context("failed to remove temporary directory", err))?;
Ok(any_entries)
}
}
fn io_error_context(context: &str, err: io::Error) -> io::Error {
io::Error::new(io::ErrorKind::Other, format!("{context}: {err}"))
}
View on GitHub (pinned to 7088e4b63a)