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

Supports for async closures #823

Closed
ShoyuVanilla opened this issue Feb 25, 2025 · 5 comments · Fixed by #824
Closed

Supports for async closures #823

ShoyuVanilla opened this issue Feb 25, 2025 · 5 comments · Fixed by #824
Assignees

Comments

@ShoyuVanilla
Copy link
Member

ShoyuVanilla commented Feb 25, 2025

c.c rust-lang/rust-analyzer#19196

I'm afraid that implementing this on chalk and using on rust-analyzer would make currently ongoing rust-analyzer's trait solver migration more difficult but we need this to improve user experiences for Rust's shiny new async closures.

  1. LangItem and WellKnownTrait for AsyncFn*
  2. TyKind for async closures. rustc categorizes them to CoroutineClosure but rust-analyzer categorizes them to Closure. I'd like to follow the rustc way for consistency but this might hinder currently ongoing trait solver migration in rust-analyzer a bit
  3. Built in AsyncFn* implementation supports for async closures and functions that returns future

I'm planning to start working on this tomorrow but if this is not welcomed due to next gen solver migrations or other issues, I'll gladly look for alternatives 😄

@compiler-errors
Copy link
Member

There is no need to add CoroutineClosure to Chalk. Please don't add it -- Rust analyzer doesn't need to know there's a difference between async || {} and || async {}, so both should lower the same. Doing any more would be unnecessary effort.

You can simply add a single built-in implementation for each AsyncFn* trait, which is:

impl<F, A, Fut, O> AsyncFn<A> for F where F: Fn<A, Output = Fut>, Fut: Future<Output = O> {}
impl<F, A, Fut, O> AsyncFnMut<A> for F where F: FnMut<A, Output = Fut>, Fut: Future<Output = O> {}
impl<F, A, Fut, O> AsyncFnOnce<A> for F where F: FnOnce<A, Output = Fut>, Fut: Future<Output = O> {}

@compiler-errors
Copy link
Member

Or if that leads to ambiguity with the blanket impls, then the impls could be restricted specifically to closures, fn pointers, and fn def self types.

@compiler-errors
Copy link
Member

For the record, this is what I said in rust-lang/rust-analyzer#18591 (comment)

@ShoyuVanilla
Copy link
Member Author

Thanks! I'll try in that way

@ShoyuVanilla
Copy link
Member Author

@rustbot claim

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

Successfully merging a pull request may close this issue.

2 participants