Skip to content

Commit 3f32505

Browse files
committed
Auto merge of #75246 - pickfire:patch-5, r=Amanieu
Add more examples to Path ends_with We faced a footgun when using ends_with to check extension, showing an example could prevent that. rust-dc/fish-manpage-completions@2c155e5
2 parents f9d1731 + 446fccf commit 3f32505

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

library/std/src/path.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -2057,9 +2057,14 @@ impl Path {
20572057
/// ```
20582058
/// use std::path::Path;
20592059
///
2060-
/// let path = Path::new("/etc/passwd");
2060+
/// let path = Path::new("/etc/resolv.conf");
2061+
///
2062+
/// assert!(path.ends_with("resolv.conf"));
2063+
/// assert!(path.ends_with("etc/resolv.conf"));
2064+
/// assert!(path.ends_with("/etc/resolv.conf"));
20612065
///
2062-
/// assert!(path.ends_with("passwd"));
2066+
/// assert!(!path.ends_with("/resolv.conf"));
2067+
/// assert!(!path.ends_with("conf")); // use .extension() instead
20632068
/// ```
20642069
#[stable(feature = "rust1", since = "1.0.0")]
20652070
pub fn ends_with<P: AsRef<Path>>(&self, child: P) -> bool {

0 commit comments

Comments
 (0)