Skip to content

Workaround rust compiler goof in Policy::translate_pk #234

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

Merged
merged 1 commit into from
Mar 11, 2021

Conversation

LLFourn
Copy link
Contributor

@LLFourn LLFourn commented Feb 16, 2021

These previously untested methods result in a compiler error if you ever tried to call them. This happens because if you put &mut in front of the type when you recursively pass it to another call you are actually creating a &mut &mut since the argument may already be a &mut. This ends up in infinite &muts prefix. The compiler only figures this out when you call the method (not at compile time of the library).

I fixed this by having an inner function take a &mut FnMut as the argument and so breaking the chain of &mut. The public functions remains the same. There might be a better way to fix this but I tried for more than an hour to do this without an inner and outer function and nothing else worked.

These previously untested methods result in a compiler error if you ever
tried to call them. This happens because if you put &mut in front of the
type when you recursively pass it to another call you are actually
creating a &mut &mut since the argument may already be a &mut. This ends
up in infinite &muts prefix. The compiler only figures this out when you call
the method (not at compile time of the library).

I fixed this by having an inner function take a &mut FnMut as the argument
and so breaking the chain of &mut. The public functions remains the same.
Copy link
Member

@sanket1729 sanket1729 left a comment

Choose a reason for hiding this comment

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

Thanks, good catch. I confirmed that the previous code did not work and only errored when the function was called.

ACK ef1d69c

@apoelstra
Copy link
Member

Oops, good catch!

And yeah, we've done the same workaround elsewhere in the code. I also cannot find a good solution :(.

Copy link
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ack ef1d69c

@apoelstra apoelstra merged commit d082cc4 into rust-bitcoin:master Mar 11, 2021
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.

3 participants