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: docs/_docs/reference/experimental/capture-checking/scoped-caps.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -50,9 +50,9 @@ Each capability has a _level_ corresponding to the local `cap` of its defining s
50
50
-**Methods** (but not accessors or constructors)
51
51
52
52
Local values like `f1`, `f2`, `ref`, etc., don't define their own levels. They inherit the level of their enclosing method or class. For example, this means:
53
-
-`f1` is at `Outer`'s level, i.e., `f` subcaptures local `cap₁`.
53
+
-`f1` is at `Outer`'s level, i.e., `f1` subcaptures local `cap₁`.
54
54
-`f2` and `ref` are both at `method`'s level, i.e., both subcapture local `cap₂`.
55
-
- By lexical lifetime, `{cap₂} <: {cap₃}` holds, but it does **not** hold that `{cap₃} <: {cap₂}`. Hence,
55
+
- By lexical nesting, `{cap₂} <: {cap₃}` holds, but it does **not** hold that `{cap₃} <: {cap₂}`. Hence,
56
56
we cannot assign the closure to `ref`, because `{f3}` is subcapture-bounded by `{cap₃}`.
57
57
58
58
### Charging Captures
@@ -248,7 +248,7 @@ Here the closure's local `cap` can absorb `f` because both are nested within `ou
248
248
249
249
## Comparison with Rust Lifetimes
250
250
251
-
Readers familiar with Rust may notice similarities to lifetime checking. Both systems prevent references from escaping their valid scope. In Rust, a reference type `&'a T` carries an explicit lifetime parameter `'a`. In Scala's capture checking, the lifetime is folded into the capability name itself: `T^{x}` says "a `T` capturing `x`," and `x`'s level implicitly determines how long this reference is valid. A capture set then acts as an upper bound on the lifetimes of all the capabilities it contains.
251
+
Readers familiar with Rust may notice similarities to lifetime checking. Both systems prevent references from escaping their valid scope. In Rust, a reference type `&'a T` carries an explicit lifetime parameter `'a`. In Scala's capture checking, the lifetime is folded into the capability name itself: `T^{x}` says "a `T` capturing `x`," and `x`'s level implicitly determines how long this reference is valid. A capture set of a reference then acts as an upper bound of the reference itself: it only lives as long as all the capabilities it contains are visible.
252
252
253
253
Consider a `withFile` pattern that ensures a file handle doesn't escape:
0 commit comments