Commit 38cd2e4
committed
Improve
What we want to show with `async fn` is that it automatically captures
all in-scope type and lifetime parameters in the returned opaque
`Future`. We're doing this to contrast it with RPIT in Rust 2021 and
earlier editions which does not capture in the returned opaque type
all in-scope lifetime parameters automatically.
However, our examples did not well demonstrate this, because the
examples used the lifetime parameters in the `async fn` return types,
which results in those lifetime parameters appearing in the associated
type of each returned opaque `Future`. In the RPIT desugarings, the
lifetime parameters would therefore appear in the bounds of the `impl
Trait` opaque types, and so would be captured regardless.
To better draw the distinction we want to draw, let's change each
`async fn` example to simply return the unit type (`()`). This
ensures that in the RPIT desugarings any lifetime parameters will not
be automatically captured under the rules of Rust 2021 and earlier
editions.
For each example, we'll use each of the type and lifetime parameters
in the body of the function so that they will appear in the returned
hidden type. This ensures that the RPIT desugarings for the examples
where a lifetime parameter is captured cannot be expressed without
using one of the tricks.
(Thanks to @tmandry for raising this important point.)async fn capturing examples1 parent 6918bcc commit 38cd2e4
1 file changed
+11
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
28 | | - | |
| 27 | + | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
47 | | - | |
| 46 | + | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | | - | |
72 | | - | |
| 71 | + | |
| 72 | + | |
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
103 | | - | |
| 103 | + | |
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
| |||
0 commit comments