You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We've been using "tracking issue" rather than "rust issue" recently,
so let's adjust that. Let's also use sentence case for the title and
remove some remaining bits left over from the RFC template. And let's
replace some Unicode characters that don't have ubiquitous font
support with ASCII equivalents.
@@ -30,8 +30,6 @@ Examples of RTN usage allowed by this RFC include:
30
30
# Motivation
31
31
[motivation]: #motivation
32
32
33
-
> Why are we doing this? What use cases does it support? What is the expected outcome?
34
-
35
33
Rust now supports async fns and `-> impl Trait` in traits (acronymized as AFIT and RPITIT, respectively), but we currently lack the ability for users to declare additional bounds on the values returned by such functions. This is often referred to as the [Send bound problem][sbp], because the most acute manifestation is the inability to require that an `async fn` returns a `Send` future, but it is actually more general than both async fns and the `Send` trait (as discussed below).
> Explain the proposal as if it was already included in the language and you were teaching it to another Rust programmer.
310
-
311
307
Async functions can be used in many ways. The most common configuration is to use a *work stealing* setup, in which spawned tasks may migrate between threads. In this case, all futures have to be `Send` to ensure that this migration is safe. But many applications prefer to use a *thread-per-core* setup, in which tasks, once spawned, never move to another thread (one important special case is where the entire application runs on a single thread to begin with, common in embedded environments but also in e.g. Google's Fuchsia operating system).
312
308
313
309
For the most part, async functions today do not declare whether they are `Send` explicitly. Instead, when a future `F` is spawned on a multithreaded executor, the compiler determines whether it implements `Send`. So long as `F` results from an `async fn` that only calls other `async fn`s, the compiler can analyze the full range of possible executions. But there are limitations, especially around calls to async trait methods like `f.method()`. If the type of `f` is either a generic type or a `dyn` trait, the compiler cannot determine which impl will be used and hence cannot analyze the function body to see if it is `Send`. This can result in compilation errors.
@@ -492,14 +488,6 @@ When using a trait `MyTrait` that defines a sendable alias `SendMyTrait`...
| Identifier "(" ".." ")" ":" TraitRef // <--- new
570
558
```
571
559
572
560
Examples: given the `Widgets` trait defined earlier in this section...
@@ -588,7 +576,7 @@ Although RTN types extend the type grammar, the compiler will not allow them to
588
576
*`dyn Widgets<widgets(..): Send>`
589
577
*`impl Widgets<widgets(..): Send>`
590
578
591
-
> *Nonnormative:* The current set of allowed locations correspond to places where generics on the method (e.g., `widgets(..)`) can be converted into higher-ranked trait bounds, as described in the next section. We expect [future RFCs](#future-possibilities) to extend the places where RTN can appear. These RFCs will detail how to manage generic parameters in those functions. The expectation is that the behavior will generally match "whatever `'_` would do". For example, `let w: W::widgets(..) = ...` would be equivalent to `let w: W::$Widgets<'_> = ...`.
579
+
> *Non-normative:* The current set of allowed locations correspond to places where generics on the method (e.g., `widgets(..)`) can be converted into higher-ranked trait bounds, as described in the next section. We expect [future RFCs](#future-possibilities) to extend the places where RTN can appear. These RFCs will detail how to manage generic parameters in those functions. The expectation is that the behavior will generally match "whatever `'_` would do". For example, `let w: W::widgets(..) = ...` would be equivalent to `let w: W::$Widgets<'_> = ...`.
592
580
593
581
## Converting to higher-ranked trait bounds
594
582
@@ -626,8 +614,6 @@ Although conceptually RTN could be used for any trait method, we choose to limit
626
614
# Drawbacks
627
615
[drawbacks]: #drawbacks
628
616
629
-
>Why should we *not* do this?
630
-
631
617
## Confusion about future type vs awaited type
632
618
633
619
When writing an async function, the future is implicit:
@@ -663,11 +649,6 @@ It is a consequence of existing precedent:
663
649
# Rationale and alternatives
664
650
[rationale and alternatives]: #rationale-and-alternatives
665
651
666
-
>- Why is this design the best in the space of possible designs?
667
-
>- What other designs have been considered and what is the rationale for not choosing them?
668
-
>- What is the impact of not doing this?
669
-
>- If this is a language proposal, could this be done in a library or macro instead? Does the proposed change make Rust code easier or harder to read, understand, and maintain?
670
-
671
652
## What is the impact of not doing this?
672
653
673
654
The Async Working Group has performed [five case studies][cs] around the use of async functions in trait, covering usage in the following scenarios:
@@ -951,8 +932,6 @@ C++ has [`decltype`](https://en.cppreference.com/w/cpp/language/decltype) expres
951
932
# Unresolved questions
952
933
[unresolved questions]: #unresolved-questions
953
934
954
-
>- What parts of the design do you expect to resolve through the implementation of this feature before stabilization?
955
-
956
935
## Does stabilizing `T::foo(..)` notation as a standalone type create a confusing inconsistency with `-> ()` shorthand?
957
936
958
937
Unlike a regular associated type, this RFC does not allow a trait bound that specifies the return type of a method, only the ability to put bounds on that return type.
@@ -965,10 +944,6 @@ Prior to stabilizing the "associated type position" syntax, we should be sure we
965
944
# Future possibilities
966
945
[future possibilities]: #future-possibilities
967
946
968
-
>Think about what the natural extension and evolution of your proposal would
969
-
be and how it would affect the language and project as a whole in a holistic
0 commit comments