{"record":{"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/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/compiler/rustc_middle/src/mir/pretty.rs#L280-L316","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before: dump dir is read-only\nRUSTFLAGS=\"-Zdump-mir -Zdump-mir-dir=/opt/mir\" cargo build\n# after: use a writable directory\nRUSTFLAGS=\"-Zdump-mir -Zdump-mir-dir=/tmp/mir-dumps\" cargo build","handlingStrategy":"validation","validationCode":"// Before compiling with -Zdump-mir, verify the output directory is creatable.\nuse std::path::Path;\n\nfn verify_dump_dir(dir: &str) -> Result<(), String> {\n    let path = Path::new(dir);\n    // Check parent is writable or path can be created\n    std::fs::create_dir_all(path).map_err(|e| format!(\"cannot create dump dir '{}': {}\", dir, e))?;\n    // Clean up test\n    if std::fs::read_dir(path).map(|mut d| d.next().is_none()).unwrap_or(true) {\n        std::fs::remove_dir(path).ok();\n    }\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":"// create_dump_file returns io::Result. In internal rustc code:\nmatch body.create_dump_file(\"mir\", &body) {\n    Ok(file) => { /* write MIR */ },\n    Err(e) => {\n        tcx.sess.dcx().warn(format!(\"failed to create MIR dump file: {e}\"));\n        // continue compilation without the dump\n    }\n}","preventionTips":["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."],"tags":["rustc","mir","dump","io","debugging","unstable-flags"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}