Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions library/std/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2107,31 +2107,31 @@ impl PartialEq for PathBuf {
impl cmp::PartialEq<str> for PathBuf {
#[inline]
fn eq(&self, other: &str) -> bool {
Path::eq(self, other)
self.as_path() == other
}
}

#[stable(feature = "eq_str_for_path", since = "CURRENT_RUSTC_VERSION")]
impl cmp::PartialEq<PathBuf> for str {
#[inline]
fn eq(&self, other: &PathBuf) -> bool {
other == self
self == other.as_path()
}
}

#[stable(feature = "eq_str_for_path", since = "CURRENT_RUSTC_VERSION")]
impl cmp::PartialEq<String> for PathBuf {
#[inline]
fn eq(&self, other: &String) -> bool {
**self == **other
self.as_path() == other.as_str()
}
}

#[stable(feature = "eq_str_for_path", since = "CURRENT_RUSTC_VERSION")]
impl cmp::PartialEq<PathBuf> for String {
#[inline]
fn eq(&self, other: &PathBuf) -> bool {
other == self
self.as_str() == other.as_path()
}
}

Expand Down Expand Up @@ -3426,15 +3426,15 @@ impl cmp::PartialEq<Path> for str {
impl cmp::PartialEq<String> for Path {
#[inline]
fn eq(&self, other: &String) -> bool {
self == &*other
self == other.as_str()
}
}

#[stable(feature = "eq_str_for_path", since = "CURRENT_RUSTC_VERSION")]
impl cmp::PartialEq<Path> for String {
#[inline]
fn eq(&self, other: &Path) -> bool {
other == self
self.as_str() == other
}
}

Expand Down
16 changes: 13 additions & 3 deletions library/std/tests/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2528,7 +2528,17 @@ fn normalize_lexically() {
}

#[test]
/// See issue#146183
fn compare_path_to_str() {
assert!(&PathBuf::from("x") == "x");
/// See issue#146183 and issue#146940
fn compare_path_like_to_str_like() {
let path_buf = PathBuf::from("x");
let path = Path::new("x");
let s = String::from("x");
assert!(path == "x");
assert!("x" == path);
assert!(path == &s);
assert!(&s == path);
assert!(&path_buf == "x");
assert!("x" == &path_buf);
assert!(path_buf == s);
assert!(s == path_buf);
}
Loading