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] Should we allow `impl Trait` after `->` in `fn` types or parentheses sugar? #45994

Open
nikomatsakis opened this Issue Nov 15, 2017 · 3 comments

Comments

Projects
None yet
3 participants
@nikomatsakis
Copy link
Contributor

nikomatsakis commented Nov 15, 2017

RFC 1951 disallowed uses of impl Trait within Fn trait sugar or higher-ranked bounds. For example, the following is disallowed:

fn foo(f: impl Fn(impl SomeTrait) -> impl OtherTrait)
fn bar() -> (impl Fn(impl SomeTrait) -> impl OtherTrait)

This tracking issue exists to discuss -- if we were to allow them -- what semantics they ought to have. Some known concerns around the syntax are:

  • Should the () switch from existential to universal quantification and back?
    • I think the general feeling here is now "no", basically because "too complex".
  • If HRTB were introduced, where would we (e.g.) want impl OtherTrait to be bound?

For consistency, we are disallow fn(impl SomeTrait) -> impl OtherTrait and dyn Fn(impl SomeTrait) -> impl OtherTrait as well. When considering the questions, one should also consider what the meaning would be in those contexts.

@est31

This comment has been minimized.

Copy link
Contributor

est31 commented May 31, 2018

Should we allow impl Trait after -> in fn types or parentheses sugar?

fn(impl SomeTrait) -> impl OtherTrait

How is impl Trait meant to work in function pointers? Do you mean Fn instead of fn?

@nikomatsakis

This comment has been minimized.

Copy link
Contributor Author

nikomatsakis commented Jun 1, 2018

@est31

How is impl Trait meant to work in function pointers? Do you mean Fn instead of fn?

I meant fn -- this basically gets at the heart of the question, which is the scoping of impl Trait. In particular, one might expect that

fn foo(x: fn(impl Trait))

would desugar to

fn foo<T: Trait>(x: fn(T))

Of course -- as you righly point out -- if the T were going to be scoped to x -- sort of like for<T: Trait> fn(T) -- we couldn't actually compile that with monomorphization (though we could do it with Fn traits, potentially).

@est31

This comment has been minimized.

Copy link
Contributor

est31 commented Jun 1, 2018

@nikomatsakis I see, thanks for the clarification!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment