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

[Refactor] Derive PartialEq for ConstValue #307

Merged
merged 1 commit into from
Jul 31, 2023
Merged

Conversation

acl-cqc
Copy link
Contributor

@acl-cqc acl-cqc commented Jul 27, 2023

AFAICT our manual implementation does exactly what the derive one would, except for one case - ConstValue::Opaque. But with a bit of "wizardry" (?!) we can get provide that ourselves and get Rust to derive the rest.

The extra level of tupling inside ConstValue::Opaque was because without that the derive(serde::Serialize) on ConstValue produced a complex error about moving out of a Box. A struct OpaqueValue(CustomType, Box<dyn CustomConst>) is one way to do that but just the tuple works too.

@acl-cqc acl-cqc requested a review from aborgna-q July 27, 2023 19:18
@acl-cqc acl-cqc changed the title [Refactor] Derive partialeq for ConstValue [Refactor] Derive PartialEq for ConstValue Jul 27, 2023
@aborgna-q
Copy link
Collaborator

aborgna-q commented Jul 31, 2023

Apparently the error that prevents us from deriving PartialEq with the barebones box is a known bug :/
rust-lang/rust#78808

Here's a minimal case. Hopefully it will be fixed some day... playground

Base automatically changed from bugfix/no_derive_const to main July 31, 2023 08:42
@acl-cqc acl-cqc requested a review from aborgna-q July 31, 2023 09:25
Copy link
Collaborator

@aborgna-q aborgna-q left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Add extra tuple to workaround rust-lang/rust#78808

Rename CustomConst::(eq => equal_consts) to disambiguate
@acl-cqc acl-cqc enabled auto-merge July 31, 2023 09:34
@acl-cqc acl-cqc added this pull request to the merge queue Jul 31, 2023
Merged via the queue into main with commit 62a801b Jul 31, 2023
6 checks passed
@acl-cqc acl-cqc deleted the refactor/derive_partialeq branch July 31, 2023 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants