@@ -334,10 +334,10 @@ fn rsplit_file_at_dot(file: &OsStr) -> (Option<&OsStr>, Option<&OsStr>) {
334
334
}
335
335
}
336
336
337
- fn split_file_at_dot ( file : & OsStr ) -> ( Option < & OsStr > , Option < & OsStr > ) {
337
+ fn split_file_at_dot ( file : & OsStr ) -> ( & OsStr , Option < & OsStr > ) {
338
338
let slice = os_str_as_u8_slice ( file) ;
339
339
if slice == b".." {
340
- return ( Some ( file) , None ) ;
340
+ return ( file, None ) ;
341
341
}
342
342
343
343
// 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>) {
346
346
// only from ASCII-bounded slices of existing &OsStr values.
347
347
let i = match slice[ 1 ..] . iter ( ) . position ( |b| * b == b'.' ) {
348
348
Some ( i) => i + 1 ,
349
- None => return ( Some ( file) , None ) ,
349
+ None => return ( file, None ) ,
350
350
} ;
351
351
let before = & slice[ ..i] ;
352
352
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) ) ) }
354
354
}
355
355
356
356
////////////////////////////////////////////////////////////////////////////////
@@ -2201,9 +2201,11 @@ impl Path {
2201
2201
/// assert_eq!("foo", Path::new("foo.rs").file_prefix().unwrap());
2202
2202
/// assert_eq!("foo", Path::new("foo.tar.gz").file_prefix().unwrap());
2203
2203
/// ```
2204
- #[ unstable( feature = "path_file_prefix" , issue = "none " ) ]
2204
+ #[ unstable( feature = "path_file_prefix" , issue = "86319 " ) ]
2205
2205
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) } )
2207
2209
}
2208
2210
2209
2211
/// Extracts the extension of [`self.file_name`], if possible.
0 commit comments