XO0802: scope handle, or a value containing a task group, escapes its scope
No task outlives its scope. A scope handle, a closure that captures one, or a value whose type contains a task.Group from s.group() cannot be the scope’s value, be returned, or be stored outside the scope (in an outer var, a collection, or a channel), because it could start tasks after the scope ended. os.tasks, the program lifetime group from main, may be stored anywhere. See core 7.1.
Example
fn f() -> Int {
let h = scope s { s }
1
}Fix
fn f() -> Int {
scope s {
let t = s.spawn(fn() { 1 })
t.await
}
}Run xo explain XO0802 for this text in a terminal, or see
section 10.6 of the specification.