rust-lang/rust · error · io::Error
IO error creating MIR dump directory
Error message
IO error creating MIR dump directory: {parent:?}; {e} What it means
Returned by create_dump_file in rustc_middle::mir::pretty when fs::create_dir_all fails while creating the parent directory for a MIR dump file. The directory path comes from the -Z dump-mir-dir unstable flag (default mir_dump/). This function is invoked when -Z dump-mir or -Z dump-mir-excluded passes are enabled, causing the compiler to write MIR state to disk for debugging.
Solutions
- Ensure the dump_mir_dir path (default: mir_dump/) is writable. Check with: ls -la . && mkdir -p mir_dump.
- Set -Z dump-mir-dir to an absolute path you control, e.g., -Z dump-mir-dir=/tmp/mir-dumps.
- If you don't need MIR dumps, remove -Z dump-mir from your RUSTFLAGS.
- Check for a file vs directory collision — if 'mir_dump' exists as a file, remove or rename it.
Example fix
# before: dump dir is read-only RUSTFLAGS="-Zdump-mir -Zdump-mir-dir=/opt/mir" cargo build # after: use a writable directory RUSTFLAGS="-Zdump-mir -Zdump-mir-dir=/tmp/mir-dumps" cargo build
Defensive patterns
Strategy: validation
Validate before calling
// Before compiling with -Zdump-mir, verify the output directory is creatable.
use std::path::Path;
fn verify_dump_dir(dir: &str) -> Result<(), String> {
let path = Path::new(dir);
// Check parent is writable or path can be created
std::fs::create_dir_all(path).map_err(|e| format!("cannot create dump dir '{}': {}", dir, e))?;
// Clean up test
if std::fs::read_dir(path).map(|mut d| d.next().is_none()).unwrap_or(true) {
std::fs::remove_dir(path).ok();
}
Ok(())
} Try / catch
// create_dump_file returns io::Result. In internal rustc code:
match body.create_dump_file("mir", &body) {
Ok(file) => { /* write MIR */ },
Err(e) => {
tcx.sess.dcx().warn(format!("failed to create MIR dump file: {e}"));
// continue compilation without the dump
}
} Prevention
- Ensure the dump_mir_dir path is writable before enabling -Zdump-mir.
- Use an absolute path like /tmp/mir-dumps for reliability.
- Remove -Zdump-mir from RUSTFLAGS when you don't need MIR output.
- Check for file-vs-directory name collisions in the dump path.
When it happens
Trigger: Compiling with RUSTFLAGS="-Zdump-mir" or -Z dump-mir-dir=<path> where the specified directory cannot be created. The parent path is derived from the dump_mir_dir option joined with the output filename.
Common situations: Setting dump_mir_dir to a path inside a read-only directory; permissions issues on the working directory; invalid path characters; the path component is a file rather than a directory; running the compiler in a sandboxed/containerized environment with restricted filesystem access.
Related errors
- IO error creating MIR dump file
- archive member at offset
- {context}: {err}
- expected monomorphic const in codegen
- Non terminating drop_in_place_real???
AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10).
Data as JSON: /api/errors/009344fca158926d.
Report an issue: GitHub.
Appendix: source
Thrown at compiler/rustc_middle/src/mir/pretty.rs:298
file_path.push(&file_name);
file_path
}
/// Attempts to open a file where we should dump a given MIR or other
/// bit of MIR-related data. Used by `mir-dump`, but also by other
/// bits of code (e.g., NLL inference) that dump graphviz data or
/// other things, and hence takes the extension as an argument.
pub fn create_dump_file(
&self,
extension: &str,
body: &Body<'tcx>,
) -> io::Result<io::BufWriter<fs::File>> {
let file_path = self.dump_path(extension, body);
if let Some(parent) = file_path.parent() {
fs::create_dir_all(parent).map_err(|e| {
io::Error::new(
e.kind(),
format!("IO error creating MIR dump directory: {parent:?}; {e}"),
)
})?;
}
fs::File::create_buffered(&file_path).map_err(|e| {
io::Error::new(e.kind(), format!("IO error creating MIR dump file: {file_path:?}; {e}"))
})
}
}
///////////////////////////////////////////////////////////////////////////
// Whole MIR bodies
/// Write out a human-readable textual representation of this crate's MIR,
/// with the default [`PrettyPrintMirOptions`].
pub fn write_mir_pretty<'tcx>(tcx: TyCtxt<'tcx>, w: &mut dyn io::Write) -> io::Result<()> {
let writer = MirWriter::new(tcx);View on GitHub (pinned to 7088e4b63a)