Skip to content

Commit 6918bcc

Browse files
committed
Move forward Captures links to footnotes
We use the `Captures` trait for exposition before formally introducing it in a later section. In an earlier commit, we had added some text in parentheses to explain this. Rather than breaking up the flow with parenthesized text, let's use footnotes for this. In the second place that we do this, we're using `Captures` only for exposition; real code would not need to use the trick here. We'll mention that in the footnote as well.
1 parent d61f380 commit 6918bcc

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

text/3498-lifetime-capture-rules-2024.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,13 @@ This RFC specifies a [solution] that achieves this. But first, we'll describe t
2121

2222
In return position `impl Trait` (RPIT) and `async fn`, an **opaque type** is a type that can only be used for its specified trait bounds (and for the "leaked" auto trait bounds of its hidden type). A **hidden type** is the actual concrete type of the values hidden behind the opaque type.
2323

24-
A hidden type is only allowed to name lifetime parameters when those lifetime parameters have been *"captured"* by the corresponding opaque type. For example:
24+
A hidden type is only allowed to name lifetime parameters when those lifetime parameters have been *"captured"* by the corresponding opaque type. For example:[^ref-captures-trait-ltps]
2525

2626
```rust
2727
// Returns: `Future<Output = &'a ()> + Captures<&'a ()>`
2828
async fn foo<'a>(x: &'a ()) -> &'a () { x }
2929
```
3030

31-
(See [below](#the-captures-trick) for the definition of `Captures`.)
32-
3331
In the above, we would say that the lifetime parameter `'a` has been captured in the returned opaque type.
3432

3533
For an opaque type that *does not* specify an outlives bound (e.g. `+ 'other`), when a caller receives a value of that opaque type and wants to prove that it outlives some lifetime, the caller must prove that all of the captured lifetime components of the opaque type outlive that lifetime. The captured lifetime components are the set of lifetimes contained within captured type parameters and the lifetimes represented by captured lifetime parameters.
@@ -38,9 +36,11 @@ For an opaque type that *does* specify an outlives bound (e.g. `+ 'other`), when
3836

3937
See [Appendix H] for examples and further exposition of these rules.
4038

39+
[^ref-captures-trait-ltps]: See ["The `Captures` trick"](#the-captures-trick) for the definition of `Captures`.
40+
4141
## Capturing lifetimes in type parameters
4242

43-
In return position `impl Trait` (RPIT) and `async fn`, lifetimes contained within all in-scope type parameters are captured in the opaque type. For example:
43+
In return position `impl Trait` (RPIT) and `async fn`, lifetimes contained within all in-scope type parameters are captured in the opaque type. For example:[^ref-captures-trait-tps]
4444

4545
```rust
4646
// Returns: Future<Output = T> + Captures<T>
@@ -55,6 +55,8 @@ fn bar<'a>(x: &'a ()) {
5555

5656
In the above, we would say that `foo` captures the type parameter `T` or that it "captures all lifetime components contained in the type parameter `T`". Consequently, the call to `foo` captures the lifetime `'a` in its returned opaque type.
5757

58+
[^ref-captures-trait-tps]: See ["The `Captures` trick"](#the-captures-trick) for the definition of `Captures`. Note that in this example, the `Captures` trick would not be needed, but it is notated explicitly for exposition.
59+
5860
### Behavior of `async fn`
5961

6062
As we saw in the examples above, `async` functions automatically capture in their returned opaque types all type and lifetime parameters in scope.

0 commit comments

Comments
 (0)