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

Comments

Projects
None yet
4 participants
@CodeSandwich
Copy link

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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link
Author

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
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.