rust-lang/rust-analyzer · error · io::Error
error creating directory {path:?}: {e}
Error message
error creating directory {path:?}: {e} What it means
An `io::Error` formatting string in `stdx`'s tempfile helper `create`: the loop joins a prefix, PID, and an internal atomic counter into a candidate path and calls the caller's `create` with `create_new(true)`; when the create callback fails for a non-collision reason, the error is wrapped with the candidate `{path}`. The input at fault is the OS-level directory/file creation under the system temp dir (permissions, disk full, or the specific callback's open options).
Source
Thrown at crates/stdx/src/tempfile.rs:98
static INTERNAL_COUNTER: AtomicU32 = AtomicU32::new(0);
pub(super) fn create<T>(
prefix: &str,
mut create: impl FnMut(OpenOptions, &Path) -> io::Result<T>,
) -> io::Result<(T, PathBuf)> {
let temp_dir = std::env::temp_dir().canonicalize()?;
let pid = std::process::id();
loop {
let path = temp_dir.join(format!(
"{prefix}{pid:x}-{:x}",
INTERNAL_COUNTER.fetch_add(1, Ordering::AcqRel),
));
let mut open_options = OpenOptions::new();
open_options.create_new(true);
match create(open_options, &path) {
Err(e) if e.kind() == ErrorKind::AlreadyExists => {}
Err(e) => {
return Err(io::Error::new(
e.kind(),
format!("error creating directory {path:?}: {e}"),
));
}
Ok(file) => {
return Ok((file, path));
}
}
}
}
}
#[cfg(any(
target_os = "linux",
target_os = "freebsd",
target_os = "openbsd",
target_os = "netbsd",
))]View on GitHub (pinned to e8f7e90aa3)
Solutions
- Check that the system temp dir (`std::env::temp_dir`) is writable and not full
- If the failure is `AlreadyExists` from a non-atomic helper, the retry loop only covers collisions produced by this helper — ensure custom create callbacks use `create_new(true)` so the loop can retry on collision
- Clear stale temp files matching the prefix that may block creation
- Surface the underlying `e` in the message to identify the exact OS error kind
Defensive patterns
Strategy: retry
When it happens
Trigger: Thrown at crates/stdx/src/tempfile.rs:98 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of rust-lang/rust-analyzer@e8f7e90aa3 (2026-09-03).
Data as JSON: /api/errors/d82a4ed2b811b657.
Report an issue: GitHub.