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
Labels
A-impl-trait Area: impl Trait. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug.

Comments

@CodeSandwich
Copy link

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

@matthewjasper matthewjasper added the A-impl-trait Area: impl Trait. Universally / existentially quantified anonymous types with static dispatch. label Feb 24, 2019
@Centril Centril added the C-bug Category: This is a bug. label Feb 25, 2019
@sfackler
Copy link
Member

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

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
Labels
A-impl-trait Area: impl Trait. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

4 participants