Skip to content

Bad type inference error message with unboxed closures #17881

Closed
@carllerche

Description

@carllerche

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions