Skip to content

Commit 7242735

Browse files
committed
rustfmt: Simplify match in project file lookup loop
This commit changes the match in `lookup_project_file` to use pattern guards.
1 parent fe5fa87 commit 7242735

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/bin/rustfmt.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,17 @@ fn lookup_project_file(dir: &Path) -> FmtResult<Option<PathBuf>> {
6565
loop {
6666
let config_file = current.join("rustfmt.toml");
6767
match fs::metadata(&config_file) {
68-
Ok(md) => {
69-
// Properly handle unlikely situation of a directory named `rustfmt.toml`.
70-
if md.is_file() {
71-
return Ok(Some(config_file));
72-
}
73-
}
74-
// If it's not found, we continue searching; otherwise something went wrong and we
75-
// return the error.
68+
// Only return if it's a file to handle the unlikely situation of a directory named
69+
// `rustfmt.toml`.
70+
Ok(ref md) if md.is_file() => return Ok(Some(config_file)),
71+
// Return the error if it's something other than `NotFound`; otherwise we didn't find
72+
// the project file yet, and continue searching.
7673
Err(e) => {
7774
if e.kind() != ErrorKind::NotFound {
7875
return Err(FmtError::from(e));
7976
}
8077
}
78+
_ => {}
8179
}
8280

8381
// If the current directory has no parent, we're done searching.

0 commit comments

Comments
 (0)