13b3294e91
Remove requirement that forces symmetric and transitive PartialEq impls to exist ### Counterexample of symmetry: If you [have](https://docs.rs/proc-macro2/1.0.24/proc_macro2/struct.Ident.html#impl-PartialEq%3CT%3E) an impl like: ```rust impl<T> PartialEq<T> for Ident where T: ?Sized + AsRef<str> ``` then Rust will not even allow the symmetric impl to exist. ```console error[E0210]: type parameter `T` must be covered by another type when it appears before the first local type (`Ident`) --> src/main.rs:9:6 | 9 | impl<T> PartialEq<Ident> for T where T: ?Sized + AsRef<str> { | ^ type parameter `T` must be covered by another type when it appears before the first local type (`Ident`) | = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local, and no uncovered type parameters appear before that first local type = note: in this case, 'before' refers to the following order: `impl<..> ForeignTrait<T1, ..., Tn> for T0`, where `T0` is the first and `Tn` is the last ``` <br> ### Counterexample of transitivity: Consider these two existing impls from `regex` and `clap`: ```rust // regex /// An inline representation of `Option<char>`. pub struct Char(u32); impl PartialEq<char> for Char { fn eq(&self, other: &char) -> bool { self.0 == *other as u32 } } ``` ```rust // clap pub(crate) enum KeyType { Short(char), Long(OsString), Position(u64), } impl PartialEq<char> for KeyType { fn eq(&self, rhs: &char) -> bool { match self { KeyType::Short(c) => c == rhs, _ => false, } } } ``` It's nice to be able to add `PartialEq<proc_macro::Punct> for char` in libproc_macro (https://github.com/rust-lang/rust/pull/80595), but it makes no sense to force an `impl PartialEq<Punct> for Char` and `impl PartialEq<Punct> for KeyType` in `regex` and `clap` in code that otherwise has nothing to do with proc macros. <br> `@rust-lang/libs` |
||
---|---|---|
.. | ||
benches | ||
src | ||
tests | ||
Cargo.toml |