-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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<Punct> for char
; symmetry for #78636
#80595
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
This will also need |
cc #78636 (comment) |
@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 |
So just so I'm understanding things, we have |
@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>`.
pub struct Char(u32);
impl PartialEq<char> for Char {
fn eq(&self, other: &char) -> bool {
self.0 == *other as u32
}
} and 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,
}
}
} 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 |
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>> for Box<U>
where T: ?Sized, U: ?Sized + PartialEq<T>
{
// …
} If the underlying EDIT: Okay, yes, you could require |
(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 |
@dtolnay I agree that adding But I don't think we need to block this particular impl on that? |
I think @dtolnay's point is that, while this |
See my comment above. My understanding is that this allows one to write |
Yes, that's correct. I also think that's enough of a justification to want this, but @dtolnay seems to disagree? |
@rfcbot fcp cancel |
@dtolnay proposal cancelled. |
Does this need its |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
@pthariensflame This will need to be updated to |
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.
e7ba8b1
to
1839748
Compare
Pushed an update to the |
@bors r+ rollup |
📌 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
This also needs |
Bumping for the |
Also fixes the "since" version of the original.
Pinging @dtolnay and @petrochenkov.