Uh oh!
There was an error while loading. Please reload this page.
impl PartialEq<Punct> for char; symmetry for #78636 - #80595
Conversation
rust-highfive
commented
Jan 1, 2021
(rust-highfive has picked a reviewer for you, use r? to override) |
pthariensflame
commented
Jan 1, 2021
This will also need |
cc #78636 (comment) |
dtolnay
commented
Jan 1, 2021
@rust-lang/libs I don't think this impl is necessary, since it is only motivated by dogmatic reasons in #78636 (comment) rather than a use case. I would prefer instead to update the symmetry and transitivity description at the top of https://doc.rust-lang.org/1.49.0/std/cmp/trait.PartialEq.html. The condition should be that if |
Team member @dtolnay has proposed to close this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
It does feel weird that one can write |
BurntSushi
commented
Jan 2, 2021
So just so I'm understanding things, we have |
dtolnay
commented
Jan 2, 2021
@BurntSushi I don't object to the specific impl, but in this case it's being added only because of the rules dictated in the PartialEq documentation, and I think that those rules are wrong. Accepting the impl but changing the rules would be fine. An example of how this goes wrong, if we don't change the rules, is that they insist every crate that defines /// An inline representation of `Option<char>`.pubstructChar(u32);implPartialEq<char>forChar{fneq(&self,other:&char) -> bool{self.0 == *other asu32}}and pub(crate)enumKeyType{Short(char),Long(OsString),Position(u64),}implPartialEq<char>forKeyType{fneq(&self,rhs:&char) -> bool{matchself{KeyType::Short(c) => c == rhs,
_ => false,}}}where those types have nothing to do with proc macros, so asking them to include a PartialEq<proc_macro::Punct> would be silly. |
Those objections seem to only apply to transitivity, though. Completing symmetry only ever requires local changes of bounded size, whereas (as has been pointed out) completing transitivity might require instances that relate two types from crates that have no access to each other, and explosively grows in the size of the changes needed. I think perhaps the requirement for transitivity should be clarified to a recommendation for transitive instances for types that are “already available for other reasons” (including those defined in the same crate) along with a “real” requirement that if a triangle of instances exists, it commutes. I don’t see any reason for dropping the symmetry requirement, though; by doing so, we ensure that anyone who does want to write and/or use generic algorithms involving |
pthariensflame
commented
Jan 2, 2021
For what it’s worth, I’d be willing to comb through |
I just thought of another reason to strongly prefer keeping symmetry a requirement: it allows instances that need to delegate to generic contents to be symmetric too. For example: impl<T,U>PartialEq<Box<T>>forBox<U>whereT: ?Sized,U: ?Sized + PartialEq<T>{// …}If the underlying EDIT: Okay, yes, you could require |
pthariensflame
commented
Jan 2, 2021
(Defining non-symmetric |
I object to both rules. For an example of why symmetry is bad, here is another example from the proc macro API: this is a great and super useful impl but the reverse impl does not typecheck. That's not a problem because 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 |
BurntSushi
commented
Jan 4, 2021
@dtolnay I agree that adding But I don't think we need to block this particular impl on that? |
pthariensflame
commented
Jan 5, 2021
I think @dtolnay's point is that, while this |
BurntSushi
commented
Jan 5, 2021
See my comment above. My understanding is that this allows one to write |
pthariensflame
commented
Jan 5, 2021
Yes, that's correct. I also think that's enough of a justification to want this, but @dtolnay seems to disagree? |
dtolnay
commented
Jan 19, 2021
dtolnay
commented
Feb 5, 2021
@rfcbot fcp cancel |
rfcbot
commented
Feb 5, 2021
@dtolnay proposal cancelled. |
Team member @dtolnay has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
pthariensflame
commented
Feb 9, 2021
Does this need its |
rfcbot
commented
Feb 10, 2021
🔔 This is now entering its final comment period, as per the review above. 🔔 |
KodrAus
commented
Feb 10, 2021
@pthariensflame This will need to be updated to |
rfcbot
commented
Feb 20, 2021
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. The RFC will be merged soon. |
Also fixes the "since" version of the original.
pthariensflame
commented
Feb 20, 2021
Pushed an update to the |
m-ou-se
commented
Feb 20, 2021
@bors r+ rollup |
bors
commented
Feb 20, 2021
📌 Commit 1839748 has been approved by |
`impl PartialEq<Punct> for char`; symmetry for rust-lang#78636 Also fixes the "since" version of the original. Pinging `@dtolnay` and `@petrochenkov.`
…laumeGomez Rollup of 7 pull requests Successful merges: - rust-lang#80595 (`impl PartialEq<Punct> for char`; symmetry for rust-lang#78636) - rust-lang#81991 (Fix panic in 'remove semicolon' when types are not local) - rust-lang#82176 (fix MIR fn-ptr pretty-printing) - rust-lang#82244 (Keep consistency in example for Stdin StdinLock) - rust-lang#82260 (rustc: Show ``@path`` usage in stable) - rust-lang#82316 (Fix minor mistake in LTO docs.) - rust-lang#82332 (Don't generate src link on dummy spans) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
pthariensflame
commented
Feb 21, 2021
This also needs |
pthariensflame
commented
Apr 6, 2021
Bumping for the |
Also fixes the "since" version of the original.
Pinging @dtolnay and @petrochenkov.