Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

impl PartialEq<{str,String}> for {Path,PathBuf} (and reversed) #105877

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
65 changes: 65 additions & 0 deletions library/std/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1885,6 +1885,38 @@ impl cmp::PartialEq for PathBuf {
}
}

#[stable(feature = "eq-str-for-path", since = "CURRENT_RUSTC_VERSION")]
impl cmp::PartialEq<str> for PathBuf {
#[inline]
fn eq(&self, other: &str) -> bool {
&*self == 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
}
}

#[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
}
}

#[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
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl Hash for PathBuf {
fn hash<H: Hasher>(&self, h: &mut H) {
Expand Down Expand Up @@ -3003,6 +3035,39 @@ impl cmp::PartialEq for Path {
}
}

#[stable(feature = "eq-str-for-path", since = "CURRENT_RUSTC_VERSION")]
impl cmp::PartialEq<str> for Path {
#[inline]
fn eq(&self, other: &str) -> bool {
let other: &OsStr = other.as_ref();
self == other
}
}

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

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

#[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
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl Hash for Path {
fn hash<H: Hasher>(&self, h: &mut H) {
Expand Down
4 changes: 3 additions & 1 deletion src/test/ui/inference/issue-72616.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ LL | if String::from("a") == "a".try_into().unwrap() {}
| |
| type must be known at this point
|
= note: multiple `impl`s satisfying `String: PartialEq<_>` found in the `alloc` crate:
= note: multiple `impl`s satisfying `String: PartialEq<_>` found in the following crates: `alloc`, `std`:
- impl PartialEq for String;
- impl PartialEq<Path> for String;
- impl PartialEq<PathBuf> for String;
- impl<'a, 'b> PartialEq<&'a str> for String;
- impl<'a, 'b> PartialEq<Cow<'a, str>> for String;
- impl<'a, 'b> PartialEq<str> for String;
Expand Down