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

Mark a few libcore types as structurally equal if their contents are #70759

Closed

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Apr 4, 2020

  • str was just missing a marker
  • arrays of StructuralEq types are already treated as StructuralEq in the rustc pattern match logic
  • tuples of StructuralEq types are also already treated as StructuralEq
  • [T] types shouldn't behave differently from arrays in pattern matching, so I marked them as StructuralEq if their contents are.
  • &T types where T: StructuralEq cannot have a custom Eq or PartialEq impl, they must be using the generic impl. Thus the user cannot have created any handwritten impls for &UserType, thus we can treat them as StructuralEq.

r? @petrochenkov

cc @pnkfelix @nikomatsakis @ecstatic-morse

cc #31434

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 4, 2020
@oli-obk oli-obk force-pushed the structurally_equal_references branch from 09f18c6 to 2219744 Compare April 4, 2020 11:00
@petrochenkov
Copy link
Contributor

What is the goal here, using Structural(Partial)Eq in bounds or removing hard-coded cases from the compiler?

Seems like these impls are not currently necessary for constant pattern matching because everything built-in is known to the compiler without them.

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 4, 2020
@ecstatic-morse
Copy link
Contributor

ecstatic-morse commented Apr 4, 2020

It's actually not correct to bound the generic parameters by Structural{Partial,}Eq. The semantics for these marker traits are quite subtle: an implementation of Structural{Partial,}Eq guarantees only that the PartialEq impl for that type calls the PartialEq impl of each of its fields. It does not guarantee that the type of each of those fields is itself Structural{Partial,}Eq.

I can try to explain why this needs to be the case, but that might be easier to do synchronously.

@nikomatsakis
Copy link
Contributor

Hmm, I wonder if all of these things are true in the face of specialization -- ah, I guess they are. e.g. the &T impls don't default a default fn, so the user should not be able to specialize it with some weird type. OK.

@nikomatsakis
Copy link
Contributor

@ecstatic-morse I don't really understand your comment, I'm afraid.

@oli-obk
Copy link
Contributor Author

oli-obk commented Apr 6, 2020

@petrochenkov
Copy link
Contributor

r? @ecstatic-morse or @eddyb
(This seems to be tied to other parts of consteval, in which I'm not an expert.)

@joelpalmer joelpalmer added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 14, 2020
@oli-obk oli-obk closed this Apr 15, 2020
@oli-obk
Copy link
Contributor Author

oli-obk commented Apr 15, 2020

This is not quite what we want, let's keep discussing in #31434

@oli-obk oli-obk deleted the structurally_equal_references branch April 15, 2020 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants