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

Fix an inference failure (fn found, different fn expected.) #184

Merged
merged 1 commit into from
Dec 24, 2014

Conversation

drbawb
Copy link
Contributor

@drbawb drbawb commented Dec 23, 2014

Using the latest nightly (rust-lang/rust@62fb41c32) I get an error such as:

rc/rust-crypto/aesni.rs:25:40: 29:10 error: match arms have incompatible types: expected `(_, fn(&[u8], aesni::KeyType, &mut [u8]) {aesni::setup_working_key_aesni_128})`, found `(_, fn(&[u8], aesni::KeyType, &mut [u8]) {aesni::setup_working_key_aesni_192})` (expected fn item, found a different fn item)
src/rust-crypto/aesni.rs:25         let (rounds, setup_function) = match key_size {
src/rust-crypto/aesni.rs:26             KeySize128 => (10, setup_working_key_aesni_128),
src/rust-crypto/aesni.rs:27             KeySize192 => (12, setup_working_key_aesni_192),
src/rust-crypto/aesni.rs:28             KeySize256 => (14, setup_working_key_aesni_256)
src/rust-crypto/aesni.rs:29         };
src/rust-crypto/aesni.rs:27:27: 27:61 note: match arm with an incompatible type
src/rust-crypto/aesni.rs:27             KeySize192 => (12, setup_working_key_aesni_192),
                                                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/rust-crypto/aesni.rs:34:9: 34:23 error: the type of this value must be known in this context
src/rust-crypto/aesni.rs:34         setup_function(key, KeyType::Encryption, e.round_keys.slice_mut(0, size(e.rounds)));
                                    ^~~~~~~~~~~~~~
src/rust-crypto/aesni.rs:34:9: 34:92 error: this function takes 1 parameter but 3 parameters were supplied [E0057]
src/rust-crypto/aesni.rs:34         setup_function(key, KeyType::Encryption, e.round_keys.slice_mut(0, size(e.rounds)));

I believe this is introduced by rust PR#19891

If you look closely you'll see rustc has tagged the expected fn-ptr with the name of the function from the first match-arm: expected``(_, fn(&[u8], aesni::KeyType, &mut [u8]) {aesni::setup_working_key_aesni_128})``

This patch declares a type without that tag and then uses that type in lieu of the inference.
Reading that PR: I do think we need to be explicit about the expected type here to trigger the coercion we want.

For some reason the inference is tagging the `fn()` for the key-setup function
with the name of the setup function. So the type inferred for the expression can only
be satisfied by the first match-arm.

Adding a type-hint seems to resolve this issue.
@DaGenix
Copy link
Owner

DaGenix commented Dec 24, 2014

Thanks!

DaGenix added a commit that referenced this pull request Dec 24, 2014
Fix an inference failure (`fn found, different fn expected.`)
@DaGenix DaGenix merged commit bb34bf5 into DaGenix:master Dec 24, 2014
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