Skip to content

Commit 001c272

Browse files
committed
More feedback from atrick
1 parent 3c1e92f commit 001c272

File tree

1 file changed

+5
-20
lines changed

1 file changed

+5
-20
lines changed

proposals/NNNN-non-escapable.md

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -305,28 +305,13 @@ struct Iterator: ~Escapable {
305305

306306
let container = ...
307307
let iterator = Iterator(container)
308-
consume container
309-
use(iterator) // 🛑 'iterator' outlives the source of its dependency
308+
consume container // `container` lifetime ends here
309+
use(iterator) // 🛑 'iterator' outlives `container`
310310
```
311311

312-
Lifetime dependencies will make this use of iterator a compile-time error.
313-
Or, as part of implementing data type internals, a nonescapable initializer may depend on a variable that is bound to a value that is only valid within that variable's local scope.
314-
Subsequent uses of the initialized nonescapable object are exactly as safe or unsafe as it would be to use the variable that the initializer depends at the same point:
315-
316-
```swift
317-
let iterator: Iterator
318-
do {
319-
let container = Container(...)
320-
let buffer = container.buffer
321-
iterator = Iterator(buffer)
322-
// `iterator` is safe as long as `buffer` is safe to use.
323-
}
324-
use(iterator) // 🛑 'iterator' outlives the source of its dependency
325-
```
326-
327-
Again, lifetime dependencies will make this use of iterator a compile-time error.
328-
Typically, a pointer is valid for the duration of its variable binding.
329-
So, in practice, nonescapable value that depends on the pointer to be available within the same scope.
312+
Lifetime dependencies will make this and similar misuses into compile-time errors.
313+
This will allow developers to safely define and use values that contain pointers into
314+
other values, ensuring that the pointers never outlive the underlying storage.
330315

331316
#### Expanding standard library types
332317

0 commit comments

Comments
 (0)