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

Decide on bounds syntax for async closures (RFC 3668) #128129

Open
traviscross opened this issue Jul 24, 2024 · 8 comments
Open

Decide on bounds syntax for async closures (RFC 3668) #128129

traviscross opened this issue Jul 24, 2024 · 8 comments
Labels
C-discussion Category: Discussion or questions that doesn't represent real issues. I-lang-nominated Nominated for discussion during a lang team meeting. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@traviscross
Copy link
Contributor

traviscross commented Jul 24, 2024

Prior to stabilization, we need to decide which syntax to use for async closure bounds. This was left as an open question in RFC 3668.

The main known candidates are:

  • F: async FnMut() -> T
  • F: AsyncFnMut() -> T

Other candidates discussed have included:

  • F: async mut fn() -> T
  • F: async mut () -> T
  • F: async mut || -> T
  • F: async fn(&mut self) -> T
  • F: AsyncFn(&mut self) -> T
  • F: async |&mut self| -> T

Tracking:

@rustbot labels +T-lang +I-lang-nominated

cc @compiler-errors @rust-lang/lang

@rustbot rustbot added needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. T-lang Relevant to the language team, which will review and decide on the PR/issue. I-lang-nominated Nominated for discussion during a lang team meeting. labels Jul 24, 2024
@traviscross traviscross removed I-lang-nominated Nominated for discussion during a lang team meeting. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jul 24, 2024
@traviscross traviscross added C-discussion Category: Discussion or questions that doesn't represent real issues. I-lang-nominated Nominated for discussion during a lang team meeting. labels Jul 24, 2024
@kennytm
Copy link
Member

kennytm commented Jul 24, 2024

Why are the 3 alternatives even considered in the first place? It feels like the team is trying to setup strawmans to divert attention away from the pros and cons between async FnMut() -> T vs AsyncFnMut() -> T.

If F: async mut || -> T is valid I would have expected F: mut || -> T should also be introduced and this is so punctuation-heavy that hurts searchability and teachability. And F: async mut fn() -> T is doubly worse because fn() -> T is already a valid type not a trait. Even if these 3 are included as experiments I highly doubt if final consensus would land on them.

@compiler-errors
Copy link
Member

compiler-errors commented Jul 24, 2024

I think at this point it's basically useless to consider anything other than async Fn or AsyncFn.

@nikomatsakis
Copy link
Contributor

nikomatsakis commented Jul 25, 2024

@kennytm

...It feels like the team is trying to setup strawmans to divert attention away...

I agree with you that we should just limit our focus to async Fn and AsyncFn.

However, this summary implies to me bad faith, and I don't think that's warranted. Those suggestions arose because there were some who felt that having some kind of syntax makes sense (for a variety of reasons, but mostly about forwards compatibility) but specifically didn't like async Fn. that said, one of the reasons I don't like those proposals is precisely that I'd expect them to also be used for synchronous functions, and I think that's a pretty invasive and unwarranted change.

@dev-ardi
Copy link
Contributor

As a user I expect that async prefacing a function desugars to the same thing but returning a future so the symmetry feels correct and more intuitive.

@mominshaikhdevs
Copy link

+1 for async

@casey
Copy link
Contributor

casey commented Aug 14, 2024

I personally find AsyncFnMut() -> T to be a little more intuitive than async FnMut() -> T.

I think the reason is that the fn keyword isn't used in function types, it's Fn and friends. If a function type could be written as fn() -> T, then I think async fn() -> T would make a lot of sense, but since it's Fn() -> T, I think the non keyword version, AsyncFn() -> T is a bit more consistent.

@mehcode
Copy link
Contributor

mehcode commented Aug 14, 2024

I think we need to take this and look in the future at other potential async traits.

If we go with F: async Fn() here I personally will want to see T: async Iterator<Item = i32>.

Likewise, if we go with F: AsyncFn(), I will want to see T: AsyncIterator<Item = i32>.

I'm not sure what I like more, to be honest. I can see T: async TRAIT to be a nice easy-to-understand syntax when it works, but from a beginner's point-of-view, I'd expect every trait to be able to be async by slapping async in front of the trait name.

@compiler-errors
Copy link
Member

compiler-errors commented Aug 14, 2024

This thread is not the right place to have discussions. Please refer to zulip: https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Async.20closures.20bounds.20syntax where a lot of this has been discussed at length.

This issue exists to track the requirement to decide this before stabilization, but like most tracking issues is not particularly a great place for discusions.

Please also refer to the RFC and the lang team notes where this was last discussed.

@rust-lang rust-lang locked as off-topic and limited conversation to collaborators Aug 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
C-discussion Category: Discussion or questions that doesn't represent real issues. I-lang-nominated Nominated for discussion during a lang team meeting. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

9 participants