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

IO error creating MIR dump file

Error message

IO error creating MIR dump file: {file_path:?}; {e}

What it means

Returned by create_dump_file in rustc_middle::mir::pretty when fs::File::create_buffered fails while creating the actual MIR dump file. The file path includes crate name, item name, pass number, pass name, disambiguator, and extension. This is the second IO step after the parent directory is successfully created.

Solutions

  1. Check the specific {file_path} in the error message for path-length or character issues.
  2. Increase the open file descriptor limit: ulimit -n 4096 or higher.
  3. Free disk space if the volume is full.
  4. On Windows, enable long path support or use a shorter dump_mir_dir.
  5. If the file_path suggests a naming collision (directory with the same name), remove the conflicting entry.

Example fix

# before: too many open files during heavy MIR dumping
ulimit -n 256  cargo build  # fails creating dump file
# after: raise the descriptor limit
ulimit -n 65536 cargo build
Defensive patterns

Strategy: validation

Validate before calling

// Before a heavy MIR-dump session, check available file descriptors and disk space.
fn check_resources_for_dump() -> Result<(), String> {
    // Check disk space (Unix)
    #[cfg(unix)]
    {
        let _ = std::fs::canonicalize(".").map_err(|e| format!("cwd error: {e}"))?;
    }
    // Check ulimit is high enough (very rough heuristic)
    Ok(())
}

Try / catch

// create_dump_file returns io::Result — handle gracefully in internal code:
match self.create_dump_file(extension, body) {
    Ok(writer) => writer,
    Err(e) => {
        tcx.sess.dcx().warn(format!("MIR dump skipped — IO error: {e}"));
        return Ok(()); // skip dump, continue compilation
    }
}

Prevention

When it happens

Trigger: Compiling with -Z dump-mir enabled; the output directory was created successfully, but opening the specific dump file fails. The full file_path is included in the error for diagnosis.

Common situations: Disk full; too many open files (ulimit -n); file path too long (especially on Windows with deep nesting); filename contains invalid characters for the OS; antivirus blocking file creation; file already exists as a directory; running in a CI environment with ephemeral/limited storage.

Related errors


AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10). Data as JSON: /api/errors/4001dba863f779c1. Report an issue: GitHub.

Appendix: source

Thrown at compiler/rustc_middle/src/mir/pretty.rs:305

    /// 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);

    writeln!(w, "// WARNING: This output format is intended for human consumers only")?;
    writeln!(w, "// and is subject to change without notice. Knock yourself out.")?;
    writeln!(w, "// HINT: See also -Z dump-mir for MIR at specific points during compilation.")?;

    let mut first = true;
    for &def_id in tcx.mir_keys(()) {

View on GitHub (pinned to 7088e4b63a)