From 51cf318dbcdd38d6a7478413513a72097d9622c3 Mon Sep 17 00:00:00 2001 From: Michael Hall Date: Tue, 17 Aug 2021 12:24:28 +1000 Subject: [PATCH] remove unnecessary empty check --- library/std/src/path.rs | 4 +--- library/std/src/path/tests.rs | 4 ++++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/library/std/src/path.rs b/library/std/src/path.rs index 9ab2f045d69..8a2450fcb88 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -2217,9 +2217,7 @@ impl Path { /// #[unstable(feature = "path_file_prefix", issue = "86319")] pub fn file_prefix(&self) -> Option<&OsStr> { - self.file_name() - .map(split_file_at_dot) - .and_then(|(before, after)| if before.is_empty() { after } else { Some(before) }) + self.file_name().map(split_file_at_dot).and_then(|(before, _after)| Some(before)) } /// Extracts the extension of [`self.file_name`], if possible. diff --git a/library/std/src/path/tests.rs b/library/std/src/path/tests.rs index d7ba4789391..e8b960e6d73 100644 --- a/library/std/src/path/tests.rs +++ b/library/std/src/path/tests.rs @@ -1127,6 +1127,8 @@ pub fn test_stem_ext() { t!(".x.y.z", file_stem: Some(".x.y"), extension: Some("z")); + t!("..x.y.z", file_stem: Some("..x.y"), extension: Some("z")); + t!("", file_stem: None, extension: None); } @@ -1168,6 +1170,8 @@ pub fn test_prefix_ext() { t!(".x.y.z", file_prefix: Some(".x"), extension: Some("z")); + t!("..x.y.z", file_prefix: Some("."), extension: Some("z")); + t!("", file_prefix: None, extension: None); }