Skip to content

Commit ccc54d9

Browse files
committed
Future direction: Lifetime dependencies between arguments
1 parent b30308d commit ccc54d9

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

proposals/NNNN-lifetime-dependency.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ Requiring an explicit mutation specification seems to us to improve readability,
420420

421421
## Future Directions
422422

423-
#### **Lifetime Dependencies for Computed Properties**
423+
#### Lifetime Dependencies for Computed Properties
424424

425425
It might be useful to allow lifetime dependencies between `self` and the value returned by a computed property.
426426
There is some ambiguity here, since resilience hides the distinction between a computed and stored property, and it’s not clear that there is any use for lifetime dependencies when returning stored properties.
@@ -447,7 +447,7 @@ This simplifies the model by identifying `~Escapable` types as exactly those typ
447447
It also helps simplify the enforcement of lifetime constraints by guaranteeing that constrained values cannot escape before being returned.
448448
We expect that in the future, additional investigation can reveal a way to relax this restriction.
449449

450-
### Downgraded Dependencies
450+
#### Downgraded Dependencies
451451

452452
```
453453
// This is forbidden by the current proposal, but could be supported in theory
@@ -459,4 +459,11 @@ It may be useful to permit “downgrading” the access so that the function can
459459
We are not confident that we can make this fully safe today: With our current diagnostic work, we cannot prevent the implementor of `f` from “sneaking” read-write access into the returned value.
460460
We hope to expand these diagnostics in the future, at which point we may be able to safely lift this restriction.
461461

462+
#### Lifetime Dependencies between arguments
462463

464+
A caller may need assurance that a callee will honor a lifetime dependency between two arguments.
465+
For example, if a function is going to destroy a container and a reference to that container in the process of computing some result,
466+
it needs to guarantee that the reference is destroyed before the container:
467+
```
468+
func f(container: consuming ContainerType, ref: borrow(container) consuming RefType) -> ResultType
469+
```

0 commit comments

Comments
 (0)