From 7e17af1b1c9e416bda96861e631744d723dd2370 Mon Sep 17 00:00:00 2001 From: Travis Finkenauer Date: Mon, 4 Aug 2025 10:38:50 -0700 Subject: [PATCH] Allow NotADirectory errors in config lookup Users may have files where directories are expected, such as "$HOME/.config" being a file when trying to lookup "$HOME/.config/rustfmt/.rustfmt.toml". We don't want to treat such situations as errors. --- src/config/mod.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/config/mod.rs b/src/config/mod.rs index b03674b6b3c..2da73e248d4 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -500,10 +500,12 @@ fn get_toml_path(dir: &Path) -> Result, Error> { // Only return if it's a file to handle the unlikely situation of a directory named // `rustfmt.toml`. Ok(ref md) if md.is_file() => return Ok(Some(config_file.canonicalize()?)), - // Return the error if it's something other than `NotFound`; otherwise we didn't - // find the project file yet, and continue searching. + // We didn't find the project file yet, and continue searching if: + // `NotFound` => file not found + // `NotADirectory` => rare case where expected directory is a file + // Otherwise, return the error Err(e) => { - if e.kind() != ErrorKind::NotFound { + if !matches!(e.kind(), ErrorKind::NotFound | ErrorKind::NotADirectory) { let ctx = format!("Failed to get metadata for config file {:?}", &config_file); let err = anyhow::Error::new(e).context(ctx); return Err(Error::new(ErrorKind::Other, err));