Skip to content

Commit 17b9f2a

Browse files
authored
Rollup merge of #107114 - Erk-:add-absolute-note-to-path-join, r=m-ou-se
Add note about absolute paths to Path::join The note already exists on `PathBuf::push`, but I think it is good to have it on `Path::join` as well since it can cause issues if you are not careful with your input.
2 parents 6e79310 + d8f8adf commit 17b9f2a

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

library/std/src/path.rs

+3
Original file line numberDiff line numberDiff line change
@@ -2531,6 +2531,8 @@ impl Path {
25312531

25322532
/// Creates an owned [`PathBuf`] with `path` adjoined to `self`.
25332533
///
2534+
/// If `path` is absolute, it replaces the current path.
2535+
///
25342536
/// See [`PathBuf::push`] for more details on what it means to adjoin a path.
25352537
///
25362538
/// # Examples
@@ -2539,6 +2541,7 @@ impl Path {
25392541
/// use std::path::{Path, PathBuf};
25402542
///
25412543
/// assert_eq!(Path::new("/etc").join("passwd"), PathBuf::from("/etc/passwd"));
2544+
/// assert_eq!(Path::new("/etc").join("/bin/sh"), PathBuf::from("/bin/sh"));
25422545
/// ```
25432546
#[stable(feature = "rust1", since = "1.0.0")]
25442547
#[must_use]

0 commit comments

Comments
 (0)