Skip to content

Commit f7cc8a6

Browse files
committed
auto merge of #11643 : kballard/rust/path-root-path, r=erickt
2 parents 18061e8 + b3c93b3 commit f7cc8a6

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/libstd/path/mod.rs

+1-1
Original file line numberDiff line numberDiff 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`.

src/libstd/path/windows.rs

+6-3
Original file line numberDiff line numberDiff 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")));

0 commit comments

Comments
 (0)