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

Bad type inference error message with unboxed closures #17881

Closed
carllerche opened this issue Oct 9, 2014 · 1 comment
Closed

Bad type inference error message with unboxed closures #17881

carllerche opened this issue Oct 9, 2014 · 1 comment

Comments

@carllerche
Copy link
Member

Given the following code:

#![feature(unboxed_closures)]
#![feature(overloaded_calls)]

fn action<T: Send, F: FnOnce<(T,), ()> + Send>(v: T, f: F) {
    f(v);
}

pub fn main() {
    let (tx, rx) = channel();

    action("zomg", move |:v| tx.send(v));
    rx.recv();
}

I get the error message:

fnonce.rs:11:5: 11:11 error: unable to infer enough type information to locate the impl of the trait `core::kinds::Send` for the type `closure`; type annotations required
fnonce.rs:11     action("zomg", move |:v| tx.send(v));
                 ^~~~~~
fnonce.rs:11:5: 11:11 note: the trait `core::kinds::Send` must be implemented because it is required by `action`
fnonce.rs:11     action("zomg", move |:v| tx.send(v));
                 ^~~~~~

This error message was quite confusing and the actual error was caused by the type inferencer not being able to figure out the type of channel(). If I change that bit to: channel::<&'static str>(), everything compiles fine.

@aturon aturon mentioned this issue Oct 16, 2014
47 tasks
@carllerche
Copy link
Member Author

This appears to be fixed. New code snippet is:

use std::sync::mpsc::*;

fn action<T: Send, F: FnOnce(T) + Send>(v: T, f: F) {
    f(v);
}

pub fn main() {
    let (tx, rx) = channel();

    action("zomg", move |v| { tx.send(v); });
    rx.recv();
}

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

No branches or pull requests

1 participant