File tree Expand file tree Collapse file tree 2 files changed +7
-4
lines changed Expand file tree Collapse file tree 2 files changed +7
-4
lines changed Original file line number Diff line number Diff line change @@ -400,7 +400,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe {
400400
401401 /// Returns a Path that represents the filesystem root that `self` is rooted in.
402402 ///
403- /// If `self` is not absolute, or vol-relative in the case of Windows, this returns None.
403+ /// If `self` is not absolute, or vol/cwd -relative in the case of Windows, this returns None.
404404 fn root_path ( & self ) -> Option < Self > ;
405405
406406 /// Pushes a path (as a byte vector or string) onto `self`.
Original file line number Diff line number Diff line change @@ -432,9 +432,12 @@ impl GenericPath for Path {
432432 }
433433
434434 fn root_path ( & self ) -> Option < Path > {
435- if self . is_absolute ( ) {
435+ if self . prefix . is_some ( ) {
436436 Some ( Path :: new ( match self . prefix {
437- Some ( VerbatimDiskPrefix ) |Some ( DiskPrefix ) => {
437+ Some ( DiskPrefix ) if self . is_absolute ( ) => {
438+ self . repr . slice_to ( self . prefix_len ( ) +1 )
439+ }
440+ Some ( VerbatimDiskPrefix ) => {
438441 self . repr . slice_to ( self . prefix_len ( ) +1 )
439442 }
440443 _ => self . repr . slice_to ( self . prefix_len ( ) )
@@ -1688,7 +1691,7 @@ mod tests {
16881691 fn test_root_path( ) {
16891692 assert_eq!( Path :: new( "a\\ b\\ c" ) . root_path( ) , None ) ;
16901693 assert_eq!( Path :: new( "\\ a\\ b\\ c" ) . root_path( ) , Some ( Path :: new( "\\ " ) ) ) ;
1691- assert_eq!( Path :: new( "C:a" ) . root_path( ) , None ) ;
1694+ assert_eq!( Path :: new( "C:a" ) . root_path( ) , Some ( Path :: new ( "C:" ) ) ) ;
16921695 assert_eq!( Path :: new( "C:\\ a" ) . root_path( ) , Some ( Path :: new( "C:\\ " ) ) ) ;
16931696 assert_eq!( Path :: new( "\\ \\ a\\ b\\ c" ) . root_path( ) , Some ( Path :: new( "\\ \\ a\\ b" ) ) ) ;
16941697 assert_eq!( Path :: new( "\\ \\ ?\\ a\\ b" ) . root_path( ) , Some ( Path :: new( "\\ \\ ?\\ a" ) ) ) ;
You can’t perform that action at this time.
0 commit comments