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

meaning of impl Fn() -> impl Trait (and potentially impl Foo<Output = impl Bar> #15

Open
nikomatsakis opened this issue Apr 10, 2023 · 0 comments

Comments

@nikomatsakis
Copy link
Contributor

Motivation

As of 2023-04-10, the compiler permits impl Foo<Output = impl Bar> but not impl Fn() -> impl Bar. There have been proposals to permit impl Trait in the latter position -- but what should it mean?

Details

This issue exists to catalog the various options.

  • In argument position:
    • fn something(f: impl Fn() -> impl Debug) could be equivalent to fn something<A,E>(f: A) where A: Fn() -> E, E: Debug, but this cannot accommodate higher-ranked signatures like impl Fn(&u32) -> impl Debug + '_.
    • fn something(f: impl Fn() -> impl Debug) could also be equivalent to fn something<A>(f: A) where A: Fn() -> _, A::Output: Debug (this is not legal syntax today, the -> _ is meant to mean "returns some type not specified). This would accommodate said signatures.
    • The same is relevant to impl Foo<Output = impl Bar>; for example to permit writing something like impl for<'a> Foo<Output<'a> = impl Bar + 'a> (not currently possible). Can we transition from current behavior to this? Not entirely backwards compatible, perhaps, but likely achievable. (Today, impl for<'a> Foo<Output<'a> = impl Bar> would assert that Output value is not dependent on 'a because the impl Bar desugars to a generic parameter outside the scope of the for.)
      cannot.
  • In return position:
    • fn something() -> impl Fn() -> impl Debug could be equivalent to type A: Fn() -> B; type B: Debug; fn something() -> A
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