{"id":"4001dba863f779c1","repo":"rust-lang/rust","slug":"io-error-creating-mir-dump-file-file-path-e","errorCode":null,"errorMessage":"IO error creating MIR dump file: {file_path:?}; {e}","messagePattern":"IO error creating MIR dump file: (.+?); (.+?)","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"compiler/rustc_middle/src/mir/pretty.rs","lineNumber":305,"sourceCode":"    /// 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);\n\n    writeln!(w, \"// WARNING: This output format is intended for human consumers only\")?;\n    writeln!(w, \"// and is subject to change without notice. Knock yourself out.\")?;\n    writeln!(w, \"// HINT: See also -Z dump-mir for MIR at specific points during compilation.\")?;\n\n    let mut first = true;\n    for &def_id in tcx.mir_keys(()) {","sourceCodeStart":287,"sourceCodeEnd":323,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_middle/src/mir/pretty.rs#L287-L323","documentation":"`create_dump_file`'s second I/O site: `fs::File::create_buffered(&file_path)` fails after the directory was created. rustc_middle wraps the OS error into a descriptive io::Error so the MIR-dump subsystem can report which file it could not open. Causes are filesystem-level (permission, read-only, name too long, EDQUOT) rather than MIR-level.","triggerScenarios":"Triggered when the dump directory was created (or already existed) but opening the individual `*.mir`/`.dot`/etc. file for writing returns Err — e.g. the path already exists as a directory, the FS rejects the name, or the volume filled between mkdir and create.","commonSituations":"Quota exhaustion (EDQUOT) on shared CI runners mid-build; a leftover directory with the same name as the dump file from a previous broken run; SELinux/AppArmor denying file creation under `target/`; path-length limits on Windows; antivirus locking newly created files on Windows.","solutions":["Remove the stale dump output tree and retry: `rm -rf target/debug/mir` (or your dump dir).","Check disk quota / free inodes (`df -i`, `quota -u`) and free space if EDQUOT/ENOSPC.","Move the dump dir off the problematic mount: pass `-Zdump-mir-dir=<writable-path>`.","On Windows/AV environments, add an exclusion for the build dir, or shorten the crate/disambiguator names producing path-length failures."],"exampleFix":"# before\nRUSTFLAGS='-Zdump-mir=all' cargo build\n# error: IO error creating MIR dump file: \".../mir/<crate>.foo.mir\"; Quota exceeded (os error 122)\n\n# after\nquota -u $USER  # inspect; free space, then:\nrm -rf target/debug/mir && RUSTFLAGS='-Zdump-mir=all' cargo build","handlingStrategy":"validation","validationCode":"// Same surface as [253], but for the file-create step.\n// Pre-check path writability and that it is not a directory / read-only file.\nuse std::path::Path;\nfn dump_file_creatable(path: &Path) -> std::io::Result<()> {\n    if path.is_dir() {\n        return Err(std::io::Error::new(std::io::ErrorKind::IsADirectory, \"path is a directory\"));\n    }\n    if let Some(parent) = path.parent() {\n        std::fs::create_dir_all(parent)?;\n    }\n    // probe-create then remove, so we know File::create will succeed\n    let _ = std::fs::OpenOptions::new().create_new(true).write_new(true).open(path)\n        .map(|f| drop(f));\n    let _ = std::fs::remove_file(path);\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":"// create_dump_file returns io::Result; branch on it per file.\nlet result = body.create_dump_file(extension, &body);\nmatch result {\n    Ok(mut writer) => {\n        if let Err(e) = render_mir(&mut writer, &body) {\n            eprintln!(\"warning: MIR write failed for {extension}: {e}\");\n        }\n    }\n    Err(e) => {\n        // file-level failure: log file_path, continue with the next body\n        eprintln!(\"warning: MIR dump file {} could not be created: {e}\", extension);\n    }\n}","preventionTips":["Ensure the dump path's parent exists and is writable (see [253]); a missing parent is the most common cause of the file-create failure too.","Avoid path collisions: include the body's def_id / pass name in the dump filename so two bodies don't fight over the same file.","Watch for read-only filesystems (overlay/remount, Docker read-only root) — these surface here even when the directory exists.","Treat dump creation as best-effort; never let a single failed dump file abort the whole compile."],"tags":["rustc","mir-dump","io-error","filesystem"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}