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
Copy file name to clipboardExpand all lines: proposals/NNNN-lifetime-dependency.md
+30-28Lines changed: 30 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,6 +14,8 @@ To reduce the burden of manually adding such annotations, we also propose inferr
14
14
15
15
This is a key requirement for the `StorageView` type (previously called `BufferView`) being discussed elsewhere, and is closely related to the proposal for `~Escapable` types.
16
16
17
+
**Edited** (Apr 12, 2024): Changed `@dependsOn` to `dependsOn` to match the current implementation.
18
+
17
19
#### See Also
18
20
19
21
***TODO**: **** Forum thread discussing this proposal
@@ -97,16 +99,16 @@ Our proposal would allow you to declare an `array.bufferReference()` method as f
The annotation `@dependsOn(self)` here indicates that the returned value must not outlive the array that produced it.
108
+
The annotation `dependsOn(self)` here indicates that the returned value must not outlive the array that produced it.
107
109
Conceptually, it is a continuation of the function's borrowing access:
108
110
the array is being borrowed by the function while the function executes and then continues to be borrowed by the `BufferReference` for as long as the return value exists.
109
-
Specifically, the `@dependsOn(self)` annotation in this example informs the compiler that:
111
+
Specifically, the `dependsOn(self)` annotation in this example informs the compiler that:
110
112
111
113
* The array must not be destroyed until after the `BufferReference<Element>` is destroyed.
112
114
This ensures that use-after-free cannot occur.
@@ -119,13 +121,13 @@ Let’s consider another hypothetical type: a `MutatingBufferReference<T>` type
We’ve written this example as a free function rather than as a method to show how this annotation syntax can be used to express constraints that apply to a particular argument.
128
-
The `@dependsOn(to)` annotation indicates that the returned value depends on the argument named `to`.
130
+
The `dependsOn(to)` annotation indicates that the returned value depends on the argument named `to`.
129
131
Because `count` is not mentioned in the lifetime dependency, that argument does not participate.
130
132
Similar to the previous example:
131
133
@@ -143,7 +145,7 @@ Here's a typical example that constructs a new `BufferReference` from an existin
0 commit comments