Skip to content

Commit a610469

Browse files
committed
Add section on allowing desugared form
1 parent 0a1ddd3 commit a610469

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

text/3185-static-async-fn-in-trait.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,24 @@ It is not a breaking change for traits to become dyn safe. We expect to make tra
232232

233233
The [impl trait initiative] is expecting to propose "impl trait in traits" (see the [explainer](https://rust-lang.github.io/impl-trait-initiative/explainer/rpit_trait.html) for a brief summary). This RFC is compatible with the proposed design.
234234

235+
## Allowing sugared and desugared forms
236+
237+
In the current proposal, `async fn`s in traits must be implemented using `async fn`. Using a desugared form is not allowed, which can preclude implementations from doing things like doing some work at call time before returning a future. It would also be backwards-incompatible for library authors to move between the sugared and desugared form.
238+
239+
Once impl trait in traits is supported, we can redefine the desugaring of `async fn` in traits in terms of that feature (similar to how `async fn` is desugared for free functions). That provides a clear path to allowing the desugared form to be used interchangeably with the `async fn` form. In other words, you should be able to write the following:
240+
241+
```rust
242+
trait Example {
243+
async fn method(&self);
244+
}
245+
246+
impl Example for ExampleType {
247+
fn method(&self) -> impl Future<Output = ()> + '_ {}
248+
}
249+
```
250+
251+
It could also be made backward-compatible for the trait to change between the sugared and desugared form.
252+
235253
## Ability to name the type of the returned future
236254

237255
This RFC does not propose any means to name the future that results from an `async fn`. That is expected to be covered in a future RFC from the [impl trait initiative]; you can read more about the [proposed design](https://rust-lang.github.io/impl-trait-initiative/explainer/rpit_names.html) in the explainer.

0 commit comments

Comments
 (0)