Skip to content

Commit f1f7bbf

Browse files
committed
refactor(toml): Simplify file/dir target inference
1 parent f38136e commit f1f7bbf

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/cargo/util/toml/targets.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -686,18 +686,18 @@ fn infer_any(entry: &DirEntry) -> Option<(String, PathBuf)> {
686686

687687
fn infer_file(entry: &DirEntry) -> Option<(String, PathBuf)> {
688688
let path = entry.path();
689-
path.file_stem()
690-
.and_then(|p| p.to_str())
691-
.map(|p| (p.to_owned(), path.clone()))
689+
let stem = path.file_stem()?.to_str()?.to_owned();
690+
Some((stem, path))
692691
}
693692

694693
fn infer_subdirectory(entry: &DirEntry) -> Option<(String, PathBuf)> {
695694
let path = entry.path();
696695
let main = path.join("main.rs");
697-
let name = path.file_name().and_then(|n| n.to_str());
698-
match (name, main.exists()) {
699-
(Some(name), true) => Some((name.to_owned(), main)),
700-
_ => None,
696+
let name = path.file_name()?.to_str()?.to_owned();
697+
if main.exists() {
698+
Some((name, main))
699+
} else {
700+
None
701701
}
702702
}
703703

0 commit comments

Comments
 (0)