Skip to content

Commit 494b0ac

Browse files
committed
Update scoped-caps
1 parent 937300f commit 494b0ac

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

docs/_docs/reference/experimental/capture-checking/scoped-caps.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ Consider this example:
8989
```scala
9090
def outer(c1: Cap^) = // level: outer
9191
val x = 1 // level: outer (vals don't create levels)
92-
val ref = Ref[() => Unit](() => ())
92+
var ref: () => Unit = () => ()
9393

9494
def inner(c2: Cap^) = // level: inner
9595
val y = 2 // level: inner
9696
val f = () => c2.use()
97-
ref.set(f) // Error: c2 would escape its level
97+
ref = f // Error: c2 would escape its level
9898

9999
class Local: // level: Local
100100
def method(c3: Cap^) = // level: method
@@ -127,14 +127,18 @@ capabilities it contains.
127127
Consider a `withFile` pattern that ensures a file handle doesn't escape:
128128

129129
```rust
130+
struct File;
131+
impl File { fn open(_path: &str) -> Option<File> { Some(File) } }
132+
130133
// Rust: the closure receives a reference bounded by 'a
131-
fn with_file<'a, R>(path: &str, f: impl FnOnce(&'a File) -> R) -> R {
134+
fn with_file<R>(path: &str, f: impl for<'a> FnOnce(&'a File) -> R) -> R {
132135
let file = File::open(path).unwrap();
133136
f(&file)
134137
}
135138

136139
fn main() {
137-
let escaped: &File;
140+
let f = File;
141+
let mut escaped: &File = &f;
138142
with_file("test.txt", |file| {
139143
escaped = file; // Error: borrowed value does not live long enough
140144
});

0 commit comments

Comments
 (0)