Skip to content

Commit 6109ef5

Browse files
Fix std::path::Path::file_name() doc
1 parent 0f4c4f8 commit 6109ef5

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/libstd/path.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -1529,8 +1529,7 @@ impl Path {
15291529

15301530
/// The final component of the path, if it is a normal file.
15311531
///
1532-
/// If the path terminates in `.`, `..`, or consists solely of a root of
1533-
/// prefix, `file_name` will return `None`.
1532+
/// If the path terminates in `..`, `file_name` will return `None`.
15341533
///
15351534
/// # Examples
15361535
///
@@ -1543,6 +1542,14 @@ impl Path {
15431542
///
15441543
/// assert_eq!(Some(os_str), path.file_name());
15451544
/// ```
1545+
///
1546+
/// # Other examples
1547+
///
1548+
/// ```
1549+
/// assert_eq!(Some(OsStr::new("foo.txt")), Path::new("foo.txt/.").file_name());
1550+
/// assert_eq!(Some(OsStr::new("foo.txt")), Path::new("foo.txt/.//").file_name());
1551+
/// assert_eq!(None, Path::new("foo.txt/..").file_name());
1552+
/// ```
15461553
#[stable(feature = "rust1", since = "1.0.0")]
15471554
pub fn file_name(&self) -> Option<&OsStr> {
15481555
self.components().next_back().and_then(|p| {

0 commit comments

Comments
 (0)