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

Derive Arbitrary for multihash_codetable::Code #366

Merged
merged 1 commit into from
Jun 26, 2024

Conversation

expede
Copy link
Contributor

@expede expede commented Jun 26, 2024

I found myself writing a newtype wrapper over Code to get an impl proptest::Arbitrary, and thought "hey, why don't I upstream this one-liner?"

I tried to keep to your libraries and conventions as much as possible (e.g. arb), but please let me know if I missed anything.

(Some of the automated checks are failing, but I'm 90% sure those failures "shouldn't" be related to this change. It's late here, so I'll double check tomorrow)

@vmx
Copy link
Member

vmx commented Jun 26, 2024

The CI failures are unrelated, i've opened #367 for a fix.

@expede
Copy link
Contributor Author

expede commented Jun 26, 2024

After #367, the tests got far enough to flag that there was a legitimate warning. However, I've now run into an edge case with the Cargo Hack action:

  50 | #[cfg_attr(feature = "arb", derive(arbitrary::Arbitrary))]
     |                                    ^^^^^^^^^^^^^^^^^^^^
     |                                    |
     |                                    unreachable call
     |                                    any code following this `match` expression is unreachable, as all arms diverge

I think this is a valid warning for the compiler to raise, but it only happens if none of the hash algorithms are enabled (which should never happen in normal use). The most pragmatic approach here is to allow the unreachable code (since it's useless without any hash algos anyway), so I did that. Please let me know if you'd prefer a different strategy. I wish that I could just allow the one derive, but it seems to not pick that up unless it's on the entire module (perhaps because it pertains to a macro?)

Copy link
Member

@vmx vmx left a comment

Choose a reason for hiding this comment

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

Thanks for the PR and figuring all the details out. The workaround the warning is totally fine.

@vmx vmx merged commit 184c287 into multiformats:master Jun 26, 2024
11 checks passed
@expede
Copy link
Contributor Author

expede commented Jun 26, 2024

Thank you!

@expede expede deleted the arbitrary-codetable branch June 26, 2024 20:59
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