rust-lang/rust · error · io::Error

IO error creating MIR dump directory: {parent:?}; {e}

Error message

IO error creating MIR dump directory: {parent:?}; {e}

What it means

`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.

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 22057b88b0)

Solutions

  1. Free disk space and ensure the dump directory's parent is writable by the rustc process.
  2. 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.
  3. Remove a conflicting file occupying the dump path: `rm -f target/debug/mir/<crate>` where a regular file blocks `create_dir_all`.
  4. 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.

Example fix

# before: target on a read-only mount
RUSTFLAGS='-Zdump-mir=all' cargo build
# error: IO error creating MIR dump directory: "target/.../mir"; Read-only file system (os error 30)

# after
RUSTFLAGS='-Zdump-mir=all -Zdump-mir-dir=/tmp/mir-dump' cargo build
Defensive patterns

Strategy: validation

Validate before calling

// create_dump_file() returns io::Result and wraps the dir-create error.
// Pre-validate that the dump root is creatable and writable BEFORE enabling MIR dump.
use std::path::Path;
fn mir_dump_root_writable(root: &Path) -> std::io::Result<()> {
    std::fs::create_dir_all(root)?;            // mimic create_dump_file's create_dir_all
    let probe = root.join(".mir_dump_probe");
    std::fs::write(&probe, b"")?;              // confirm write permission
    let _ = std::fs::remove_file(&probe);
    Ok(())
}
// Gate the compiler flag on this:
//   mir_dump_root_writable(Path::new(dump_dir))
//       .unwrap_or_else(|e| panic!("refusing to enable -Zmir-dump into {dump_dir}: {e}"));

Try / catch

// Handle the returned io::Result instead of letting it propagate as a hard error.
match body.create_dump_file(extension, &body) {
    Ok(writer) => {
        // write the MIR / graphviz payload
    }
    Err(e) => {
        // graceful degradation: log and skip this dump, keep compiling
        eprintln!("warning: could not create MIR dump directory ({e}); skipping dump");
        // optionally retry once after mkdir -p on the reported parent
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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/`.

Related errors


AI-assisted analysis of rust-lang/rust@22057b88b0 (2026-08-03). Data as JSON: /data/errors/009344fca158926d.json. Report an issue: GitHub.