{"id":"009344fca158926d","repo":"rust-lang/rust","slug":"io-error-creating-mir-dump-directory-parent","errorCode":null,"errorMessage":"IO error creating MIR dump directory: {parent:?}; {e}","messagePattern":"IO error creating MIR dump directory: (.+?); (.+?)","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"compiler/rustc_middle/src/mir/pretty.rs","lineNumber":298,"sourceCode":"\n        file_path.push(&file_name);\n\n        file_path\n    }\n\n    /// Attempts to open a file where we should dump a given MIR or other\n    /// bit of MIR-related data. Used by `mir-dump`, but also by other\n    /// bits of code (e.g., NLL inference) that dump graphviz data or\n    /// other things, and hence takes the extension as an argument.\n    pub fn create_dump_file(\n        &self,\n        extension: &str,\n        body: &Body<'tcx>,\n    ) -> io::Result<io::BufWriter<fs::File>> {\n        let file_path = self.dump_path(extension, body);\n        if let Some(parent) = file_path.parent() {\n            fs::create_dir_all(parent).map_err(|e| {\n                io::Error::new(\n                    e.kind(),\n                    format!(\"IO error creating MIR dump directory: {parent:?}; {e}\"),\n                )\n            })?;\n        }\n        fs::File::create_buffered(&file_path).map_err(|e| {\n            io::Error::new(e.kind(), format!(\"IO error creating MIR dump file: {file_path:?}; {e}\"))\n        })\n    }\n}\n\n///////////////////////////////////////////////////////////////////////////\n// Whole MIR bodies\n\n/// Write out a human-readable textual representation of this crate's MIR,\n/// with the default [`PrettyPrintMirOptions`].\npub fn write_mir_pretty<'tcx>(tcx: TyCtxt<'tcx>, w: &mut dyn io::Write) -> io::Result<()> {\n    let writer = MirWriter::new(tcx);","sourceCodeStart":280,"sourceCodeEnd":316,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_middle/src/mir/pretty.rs#L280-L316","documentation":"`create_dump_file` in rustc_middle's MIR pretty-printer fails to `create_dir_all` on the parent directory of the requested MIR dump path. This is an I/O error surfaced (not a panic) from the compiler when `-Zdump-mir` / `-Zdump-mir-dir` cannot create the output directory, wrapping the underlying OS errno into a descriptive io::Error.","triggerScenarios":"Triggered when running rustc/cargo with `-Zdump-mir=...` (or code paths that dump MIR/graphviz like NLL inference) and `fs::create_dir_all(parent)` returns Err — e.g. the configured dump dir resolves to a path under a read-only mount, a parent that exists as a file, ENOSPC, or permission denied.","commonSituations":"Dump dir under `target/` on a full disk; `MIR_DUMP_DIR` / `-Zdump-mir-dir=...` pointing at a path whose parent is not writable (CI container with read-only `target`); NFS/SMB mount returning EROFS; long path or invalid characters on Windows; running as a different user than the one that owns `target/`.","solutions":["Free disk space and ensure the dump directory's parent is writable by the rustc process.","Point the dump dir at a fresh writable location: `-Zdump-mir-dir=/tmp/mir-dump` (or set the env var your harness uses) and retry.","Remove a conflicting file occupying the dump path: `rm -f target/debug/mir/<crate>` where a regular file blocks `create_dir_all`.","On CI, run `cargo clean` before the dump-producing step or mount `target/` on a writable volume, and verify UID/GID match the build user."],"exampleFix":"# before: target on a read-only mount\nRUSTFLAGS='-Zdump-mir=all' cargo build\n# error: IO error creating MIR dump directory: \"target/.../mir\"; Read-only file system (os error 30)\n\n# after\nRUSTFLAGS='-Zdump-mir=all -Zdump-mir-dir=/tmp/mir-dump' cargo build","handlingStrategy":"validation","validationCode":"// create_dump_file() returns io::Result and wraps the dir-create error.\n// Pre-validate that the dump root is creatable and writable BEFORE enabling MIR dump.\nuse std::path::Path;\nfn mir_dump_root_writable(root: &Path) -> std::io::Result<()> {\n    std::fs::create_dir_all(root)?;            // mimic create_dump_file's create_dir_all\n    let probe = root.join(\".mir_dump_probe\");\n    std::fs::write(&probe, b\"\")?;              // confirm write permission\n    let _ = std::fs::remove_file(&probe);\n    Ok(())\n}\n// Gate the compiler flag on this:\n//   mir_dump_root_writable(Path::new(dump_dir))\n//       .unwrap_or_else(|e| panic!(\"refusing to enable -Zmir-dump into {dump_dir}: {e}\"));","typeGuard":null,"tryCatchPattern":"// Handle the returned io::Result instead of letting it propagate as a hard error.\nmatch body.create_dump_file(extension, &body) {\n    Ok(writer) => {\n        // write the MIR / graphviz payload\n    }\n    Err(e) => {\n        // graceful degradation: log and skip this dump, keep compiling\n        eprintln!(\"warning: could not create MIR dump directory ({e}); skipping dump\");\n        // optionally retry once after mkdir -p on the reported parent\n    }\n}","preventionTips":["Point `-Z mir-dump` / `MIR_DUMP_DIR` (or your tool's dump root) at a directory you own and have already created; avoid letting the compiler invent nested paths on a read-only mount.","On CI/sandboxed runners, confirm the dump target is writable and has free inodes/space before enabling MIR dumping — dump dirs grow large quickly.","Don't run two parallel compilations into the same dump directory; concurrent create_dir_all / File::create can race and one side will surface this error.","Treat MIR dumping as optional debug output: wrap it so a failed dump never aborts the real build."],"tags":["rustc","mir-dump","io-error","filesystem"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}