Skip to content

Commit a514d3b

Browse files
committed
Clarify section about associated types being reserved
We specify that the details about the traits, including the associated types, are implementation details. Let's make the section describing this, with respect to the associated types, more clear and give an example. (Thanks to RalfJ and Yosh for raising that this section could be clarified.)
1 parent 6000a0c commit a514d3b

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

text/3668-async-closure.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,34 @@ pub trait AsyncFn<Args>: AsyncFnMut<Args> {
193193

194194
### Associated types of `AsyncFn*` traits are not nameable
195195

196-
Note that, unlike what is true today with the current `Fn*` traits, this RFC reserves as an implementation detail the associates types of the `AsyncFn*` traits, and these will not be nameable as part of the stable interface specified by this RFC.
196+
Unlike what is true today with the current `Fn*` traits, this RFC reserves as an implementation detail the associated types of the `AsyncFn*` traits, and these will not be nameable as part of the stable interface specified by this RFC.
197+
198+
That is, using the existing `FnOnce` trait, we can write this today on stable Rust:
199+
200+
```rust
201+
fn foo<F, T>()
202+
where
203+
F: FnOnce() -> T,
204+
F::Output: Send, //~ OK
205+
{
206+
}
207+
```
208+
209+
(We decided to allow this in [#34365](https://github.com/rust-lang/rust/pull/34365).)
210+
211+
However, this RFC reserves as an implementation detail the associated types of the traits specified above, so this does not work:
212+
213+
```rust
214+
fn foo<F, T>()
215+
where
216+
F: async FnOnce() -> T,
217+
F::Output: Send,
218+
//~^ ERROR use of unstable library feature
219+
F::CallOnceFuture: Send,
220+
//~^ ERROR use of unstable library feature
221+
{
222+
}
223+
```
197224

198225
### `async` bound modifier on `Fn()` trait bounds
199226

0 commit comments

Comments
 (0)