This is the doc for open discussion within wg-async about various design questions and other topics. Please feel free to propose a topic below.
On the day of the meeting, we'll do a quick poll to sort the topics by interest and then go through them one by one. If you have a brief (under 5 min) introduction prepared for the group, we'll take that into account as we prioritize the topics.
open-discussion
Leave discussion topics below.
tmandry: Placeholder for discussing any interesting feedback we got.
Discussion threads:
Summary:
+ Send
, + 'static
etc.tmandry: Summary of lang team discussion yesterday and the upcoming one for next week.
Yesterday: Return Position Impl Trait in Trait Stabilization
#[refine]
is worth it (RFC 3245). MVP will not allow you to write impls that require #[refine]
, i.e., you cannot add extra information like a concrete type or additional bounds to your impl.#[refine]
, so you can write
trait Foo {
fn foo(&self) -> impl Future<Output = ()> + Send + '_;
// ^^^^^^
}
async fn
in an impl, once that's stable.Next week: Associated return types / Return type notation
eholk: Don't love the idea of using an attribute for semantically meaningful things (#[refine]
)
tmandry: I conceptualize it more as a lint. Semantics are the thing you put in the signature.
eholk: That makes sense
tmandry: Kind of like a shorter #[allow(...)]
. Maybe we'd stabilize as #[allow(refine)]
?
eholk: That also looks weird, maybe an argument for just #[refine]
. Code smell when you #[allow(..)]
a lot
tmandry: Mod-level #![allow(..)]
can work
async fn
desugaring and RPITITtmandry: Let's say you have
trait Foo {
async fn foo(&self, x: &i32);
}
What does this desugar to? You might think it's something like
trait Foo {
fn foo<'a, 'b>(&'a self, x: &'b i32)
-> impl Future<Output = ()> + 'a + 'b;
}
but this promises that the return type outlives 'a
and 'b
, but in reality async fn doesn't promise that. It allows the return type to name both 'a
and 'b
, and therefore the return type must be valid while both 'a
and 'b
are valid, but that's not the same as saying it outlives both 'a
and 'b
.
it's really more like
trait Captures<T> {}
impl<T, U> Captures<T> for U {}
trait Foo {
fn foo<'a, 'b>(&'a self, x: &'b i32)
-> impl Future<Output = ()> + Captures<(&'a (), &'b ())>;
}
The only function of the Captures
trait is to let you mention 'a
and 'b
in the RPITIT, which by the RPITIT rules then allows you to capture those lifetimes in the actual return type.
We can imagine new syntax for this:
trait Foo {
fn foo<'a, 'b>(&'a self, x: &'b i32)
-> impl<'a, 'b> Future<Output = ()>;
}
So, what are we doing in the RFC?
Captures
trick with async fn
, but it's ugly.+ 'a + 'b
, I'm not sure with async fn
in the future. We might find a way to make it work, but you might just need to wait for AFIT to stabilize.eholk: Can I migrate a trait from -> impl Future + '_
to async fn
in the future? In other words, are -> impl Future + '_
and async fn
exactly sugar for each other?
tmandry: Yes, when there's one lifetime, but not for multiple lifetimes.
eholk: What does fn foo(&self, _: &i32) -> impl Future<Output = ()> + '_
correspond to then?
eholk: The capture rules are starting to make me a little concerned. Because AFIT is really desirable, I expect we'll start seeing a lot of -> impl Future
traits show up in the ecosystem once RPITIT is stabilized. Once AFIT becomes available, crates may want to rewrite their -> impl Future
traits as async fn
, but to do that we need to make sure they can write -> impl Future
in a forward-compatible way. It sounds like that's going to be possible but easy to get wrong with the current plan.
eholk: To be clear though, I don't want to block RPITIT, I think it's a good feature that we should add. I want to make sure we can avoid future footguns though.
name: prompt
name: prompt
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Syncing