Stray thought that came up in conversations with @Argorak the other day: what if async closures didn't need the `async` keyword?
The trait would still be AsyncFn (or similar), and that'd be the marker for whether it's an async closure. Unlike `move`, `async` is never optional.
-
Show this thread
-
E.g. in regular closures you can often add `move` to change semantic meaning: foo(|x| x * x); // borrows foo(move |x| x * x); // takes ownership But `async` would never be optional: foo(async |x| x * x); foo(|x| x * x); // compile error So why not infer?
4 replies 0 retweets 2 likesShow this thread -
In a way this is how blocks already behave; they already apply inference: async fn foo() { { /* this block supports .await */ } } Which is different from "async blocks" which are a construct to create a *new* future (value). Does that make sense?
1 reply 0 retweets 1 likeShow this thread -
Usual disclosure: I'm not on the lang team, nor am I a language designer so please interpret this accordingly (:
3 replies 0 retweets 0 likesShow this thread -
Replying to @yoshuawuyts @Argorak
This would probably open up a number of weird corner cases. E.g. what if a closure is used as both sync & async? What if the surroundings change so that an async closure becomes sync? Would the error messages point to the right span?
1 reply 0 retweets 5 likes -
I think you're asking the right questions. Especially the first one: my guess is that would "just break" and say it can't infer the right one for both cases -- e.g. pick one. But how to teach the inference engine that? Good q; might not be worth it.
1 reply 0 retweets 2 likes
Though for the second one: if surroundings change, and an async closure becomes sync, I'd argue in many cases that's a feature -- that's why type inference is so cool! (e.g. switching form Stream -> Iterator). Should def not come at the expense of good diagnostics; big agree!
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.