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

impl trait from unboxed_closure does not accept closures #58708

Closed
CodeSandwich opened this issue Feb 24, 2019 · 2 comments
Closed

impl trait from unboxed_closure does not accept closures #58708

CodeSandwich opened this issue Feb 24, 2019 · 2 comments

Comments

@CodeSandwich
Copy link

@CodeSandwich CodeSandwich commented Feb 24, 2019

It's impossible to pass closure to a generic fn with impl trait argument when the trait comes from unboxed_closure feature.

This compiles (uses impl Fn with arrow):

fn main() {
    baz(|x| x);
}

fn baz(_: impl Fn(bool) -> bool) {}

But this fails (uses impl trait from unboxed_closure):

fn main() {
    bar(|x| x);
}

fn bar(_: impl Fn<bool, Output = bool>) {}

Returns error:

found signature of `fn(_) -> _`
expected signature of `fn(bool) -> _`

Precise definition of closure's types does not help.
Playground

@sfackler
Copy link
Member

@sfackler sfackler commented Feb 25, 2019

The desugared version of Fn(bool) -> bool is Fn<(bool,), Output = bool> - the first generic argument has to be a tuple not a bare value.

@CodeSandwich
Copy link
Author

@CodeSandwich CodeSandwich commented Feb 25, 2019

Oh my goodness, of course! Sorry for the noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants