sync function field loses sync: let r = b.run; r(1) is refused with NK2202Open and answer this issue on GitHub.
ready · opened 2026-11-01 · updated 2026-11-01 · 0 comments
A field typed fn(i64) -> i64 sync (Part I, the Button example) can be called directly inside a sync function, but once it is read into a local, the call through the local is refused as one that can pause. The prover builder met it while moving prove.rs (#125).
Probe (0.0.1335):
struct Holder {
run: fn(i64) -> i64 sync,
}
fn take(b: ref Holder) -> i64 sync {
let r = b.run
return r(1)
}
fn main() {
let b = Holder { run: fn(x) { x + 1 } }
print(take(b))
}
error[NK2202]: `take` is `sync`, but it calls `r`, which can pause.
= note: `r` isn't declared `sync` in this program.
return b.run(1) in the same function compiles and prints 2. Without sync on the field type the refusal is right (Part II 12.2: where the compiler cannot tell it does not guess); with it, the local’s type carries the promise.
sync function type (read from a field, a let with that type, a result) is callable inside a sync body; the sync check reads the callee’s type, not only its declaration.tests/compiler/: the probe prints 2; the same with the field typed without sync keeps NK2202.