about summary refs log tree commit diff
path: root/library/std/src/path.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-11-14 06:30:18 +0000
committerbors <bors@rust-lang.org>2022-11-14 06:30:18 +0000
commit96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef (patch)
tree8fb6205431371f9923ca9eac04bbcbc0ce4c2e55 /library/std/src/path.rs
parentf90a4ff26c9743abf612f015c4398d7158b646b6 (diff)
parent4fdd944af46e074807f132d46135f2945b57d1b0 (diff)
downloadrust-96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef.tar.gz
rust-96ddd32c4bfb1d78f0cd03eb068b1710a8cebeef.zip
Auto merge of #104387 - Manishearth:rollup-9e551p5, r=Manishearth
Rollup of 9 pull requests

Successful merges:

 - #103709 (ci: Upgrade dist-x86_64-netbsd to NetBSD 9.0)
 - #103744 (Upgrade cc for working is_flag_supported on cross-compiles)
 - #104105 (llvm: dwo only emitted when object code emitted)
 - #104158 (Return .efi extension for EFI executable)
 - #104181 (Add a few known-bug tests)
 - #104266 (Regression test for coercion of mut-ref to dyn-star)
 - #104300 (Document `Path::parent` behavior around relative paths)
 - #104304 (Enable profiler in dist-s390x-linux)
 - #104362 (Add `delay_span_bug` to `AttrWrapper::take_for_recovery`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'library/std/src/path.rs')
-rw-r--r--library/std/src/path.rs13
1 files changed, 12 insertions, 1 deletions
diff --git a/library/std/src/path.rs b/library/std/src/path.rs
index 9d63281627d..af88b9070c1 100644
--- a/library/std/src/path.rs
+++ b/library/std/src/path.rs
@@ -2142,7 +2142,10 @@ impl Path {
 
     /// Returns the `Path` without its final component, if there is one.
     ///
-    /// Returns [`None`] if the path terminates in a root or prefix.
+    /// This means it returns `Some("")` for relative paths with one component.
+    ///
+    /// Returns [`None`] if the path terminates in a root or prefix, or if it's
+    /// the empty string.
     ///
     /// # Examples
     ///
@@ -2156,6 +2159,14 @@ impl Path {
     /// let grand_parent = parent.parent().unwrap();
     /// assert_eq!(grand_parent, Path::new("/"));
     /// assert_eq!(grand_parent.parent(), None);
+    ///
+    /// let relative_path = Path::new("foo/bar");
+    /// let parent = relative_path.parent();
+    /// assert_eq!(parent, Some(Path::new("foo")));
+    /// let grand_parent = parent.and_then(Path::parent);
+    /// assert_eq!(grand_parent, Some(Path::new("")));
+    /// let great_grand_parent = grand_parent.and_then(Path::parent);
+    /// assert_eq!(great_grand_parent, None);
     /// ```
     #[stable(feature = "rust1", since = "1.0.0")]
     #[doc(alias = "dirname")]