diff options
| author | Michael Hall <michael@mbh.sh> | 2021-06-24 13:45:56 +1000 |
|---|---|---|
| committer | Michael Hall <michael@mbh.sh> | 2021-06-24 13:45:56 +1000 |
| commit | fcb1ebf1945c616365c74e95666dcdcfdc8bbd70 (patch) | |
| tree | 50f5ddad133ddc11c8f9cd67d8d79b46d872eb5b /library/std/src | |
| parent | a889529e984f1d477153e60c16fa4066d8b6c9d7 (diff) | |
| download | rust-fcb1ebf1945c616365c74e95666dcdcfdc8bbd70.tar.gz rust-fcb1ebf1945c616365c74e95666dcdcfdc8bbd70.zip | |
change return signature for split_file_at_dot
Diffstat (limited to 'library/std/src')
| -rw-r--r-- | library/std/src/path.rs | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/library/std/src/path.rs b/library/std/src/path.rs index 17e47b76cad..1cb596d691c 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -334,10 +334,10 @@ fn rsplit_file_at_dot(file: &OsStr) -> (Option<&OsStr>, Option<&OsStr>) { } } -fn split_file_at_dot(file: &OsStr) -> (Option<&OsStr>, Option<&OsStr>) { +fn split_file_at_dot(file: &OsStr) -> (&OsStr, Option<&OsStr>) { let slice = os_str_as_u8_slice(file); if slice == b".." { - return (Some(file), None); + return (file, None); } // 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>) { // only from ASCII-bounded slices of existing &OsStr values. let i = match slice[1..].iter().position(|b| *b == b'.') { Some(i) => i + 1, - None => return (Some(file), None), + None => return (file, None), }; let before = &slice[..i]; let after = &slice[i + 1..]; - unsafe { (Some(u8_slice_as_os_str(before)), Some(u8_slice_as_os_str(after))) } + unsafe { (u8_slice_as_os_str(before), Some(u8_slice_as_os_str(after))) } } //////////////////////////////////////////////////////////////////////////////// @@ -2201,9 +2201,11 @@ impl Path { /// assert_eq!("foo", Path::new("foo.rs").file_prefix().unwrap()); /// assert_eq!("foo", Path::new("foo.tar.gz").file_prefix().unwrap()); /// ``` - #[unstable(feature = "path_file_prefix", issue = "none")] + #[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)| before.or(after)) + self.file_name() + .map(split_file_at_dot) + .and_then(|(before, after)| if before.is_empty() { after } else { Some(before) }) } /// Extracts the extension of [`self.file_name`], if possible. |
