Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 68e8351

Browse files
authored
Unrolled build for rust-lang#123716
Rollup merge of rust-lang#123716 - Kriskras99:patch-2, r=Mark-Simulacrum Update documentation of Path::to_path_buf and Path::ancestors `Path::to_path_buf` > Changes the example from using the qualified path of PathBuf with an import. This is what's done in all other Path/PathBuf examples and makes the code look a bit cleaner. `Path::ancestors` > If you take a quick glance at the documentation for Path::ancestors, the unwraps take the natural focus. Potentially indicating that ancestors might panic. In the reworked version I've also moved the link with parent returning None and that the iterator will always yield &self to before the yield examples. Feel free to cherry-pick the changes you like.
2 parents 3a0db6c + 6b0d366 commit 68e8351

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

library/std/src/path.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2143,10 +2143,10 @@ impl Path {
21432143
/// # Examples
21442144
///
21452145
/// ```
2146-
/// use std::path::Path;
2146+
/// use std::path::{Path, PathBuf};
21472147
///
21482148
/// let path_buf = Path::new("foo.txt").to_path_buf();
2149-
/// assert_eq!(path_buf, std::path::PathBuf::from("foo.txt"));
2149+
/// assert_eq!(path_buf, PathBuf::from("foo.txt"));
21502150
/// ```
21512151
#[rustc_conversion_suggestion]
21522152
#[must_use = "this returns the result of the operation, \
@@ -2278,10 +2278,9 @@ impl Path {
22782278
/// Produces an iterator over `Path` and its ancestors.
22792279
///
22802280
/// The iterator will yield the `Path` that is returned if the [`parent`] method is used zero
2281-
/// or more times. That means, the iterator will yield `&self`, `&self.parent().unwrap()`,
2282-
/// `&self.parent().unwrap().parent().unwrap()` and so on. If the [`parent`] method returns
2283-
/// [`None`], the iterator will do likewise. The iterator will always yield at least one value,
2284-
/// namely `&self`.
2281+
/// or more times. If the [`parent`] method returns [`None`], the iterator will do likewise.
2282+
/// The iterator will always yield at least one value, namely `Some(&self)`. Next it will yield
2283+
/// `&self.parent()`, `&self.parent().and_then(Path::parent)` and so on.
22852284
///
22862285
/// # Examples
22872286
///

0 commit comments

Comments
 (0)