diff --git a/library/std/src/path.rs b/library/std/src/path.rs index ef8a14be73d18..0c4853dedacc8 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -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) { @@ -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) { diff --git a/src/test/ui/inference/issue-72616.stderr b/src/test/ui/inference/issue-72616.stderr index 6ee0626cab857..4e3fe8e77c1aa 100644 --- a/src/test/ui/inference/issue-72616.stderr +++ b/src/test/ui/inference/issue-72616.stderr @@ -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;