Skip to content

Commit

Permalink
remove unnecessary empty check
Browse files Browse the repository at this point in the history
  • Loading branch information
mbhall88 committed Aug 17, 2021
1 parent 1e759be commit 51cf318
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 1 addition & 3 deletions library/std/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions library/std/src/path/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 51cf318

Please sign in to comment.