Skip to content

Commit fcb1ebf

Browse files
committed
change return signature for split_file_at_dot
1 parent a889529 commit fcb1ebf

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

library/std/src/path.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -334,10 +334,10 @@ fn rsplit_file_at_dot(file: &OsStr) -> (Option<&OsStr>, Option<&OsStr>) {
334334
}
335335
}
336336

337-
fn split_file_at_dot(file: &OsStr) -> (Option<&OsStr>, Option<&OsStr>) {
337+
fn split_file_at_dot(file: &OsStr) -> (&OsStr, Option<&OsStr>) {
338338
let slice = os_str_as_u8_slice(file);
339339
if slice == b".." {
340-
return (Some(file), None);
340+
return (file, None);
341341
}
342342

343343
// The unsafety here stems from converting between &OsStr and &[u8]
@@ -346,11 +346,11 @@ fn split_file_at_dot(file: &OsStr) -> (Option<&OsStr>, Option<&OsStr>) {
346346
// only from ASCII-bounded slices of existing &OsStr values.
347347
let i = match slice[1..].iter().position(|b| *b == b'.') {
348348
Some(i) => i + 1,
349-
None => return (Some(file), None),
349+
None => return (file, None),
350350
};
351351
let before = &slice[..i];
352352
let after = &slice[i + 1..];
353-
unsafe { (Some(u8_slice_as_os_str(before)), Some(u8_slice_as_os_str(after))) }
353+
unsafe { (u8_slice_as_os_str(before), Some(u8_slice_as_os_str(after))) }
354354
}
355355

356356
////////////////////////////////////////////////////////////////////////////////
@@ -2201,9 +2201,11 @@ impl Path {
22012201
/// assert_eq!("foo", Path::new("foo.rs").file_prefix().unwrap());
22022202
/// assert_eq!("foo", Path::new("foo.tar.gz").file_prefix().unwrap());
22032203
/// ```
2204-
#[unstable(feature = "path_file_prefix", issue = "none")]
2204+
#[unstable(feature = "path_file_prefix", issue = "86319")]
22052205
pub fn file_prefix(&self) -> Option<&OsStr> {
2206-
self.file_name().map(split_file_at_dot).and_then(|(before, after)| before.or(after))
2206+
self.file_name()
2207+
.map(split_file_at_dot)
2208+
.and_then(|(before, after)| if before.is_empty() { after } else { Some(before) })
22072209
}
22082210

22092211
/// Extracts the extension of [`self.file_name`], if possible.

0 commit comments

Comments
 (0)