Repository navigation
Mark kj_rs::new_callbacks_promise_future unsafe - #8454
Conversation
The function takes ownership of the kj::_::PromiseNode that a KjPromiseNodeImpl points to, and later has the descriptor's unwrap callback write the promise's result into a MaybeUninit<T> for a T that the caller chooses. KjPromiseNodeImpl has public fields and is Copy, so as a safe function it accepted any pointer, the same node twice, or the wrong T. Its only caller is the bridge macro, which passes the descriptor that C++ built from a kj::Promise<T> and already makes the call in an unsafe block. Make the function unsafe and document that contract.
There was a problem hiding this comment.
✅ Approved — No issues found: the function is now unsafe with its contract documented, the existing generated call site already runs inside an unsafe block, and a compile test checks the new requirement.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
📋 Code Quality: ✅ LGTM
The unsafe marking matches the function's real preconditions (an owned raw PromiseNode and a result type the caller picks). The one generated call site in expand.rs sits inside the existing unsafe dispatch block. The new wd_rust_compile_test target and snippet check that a call without unsafe is rejected.
📝 Documentation: ✅ LGTM
The new doc comment and # Safety section describe the code as it is now and state the caller's obligations clearly.
Reviewed commit: 1bb4c892
This marks
kj_rs::new_callbacks_promise_futureasunsafe, since it adopts a raw promise node and trusts the caller's choice of result type.The function is what a generated bridge calls to turn the
KjPromiseNodeImplreturned by anasyncC++ function into a Rust future. It takes the descriptor'snodepointer as an ownedkj::_::PromiseNodeand later has theunwrapcallback write the result into aMaybeUninit<T>, for aTthe caller picks.KjPromiseNodeImplhas public fields and isCopy, so safe code could hand it any pointer, the same node twice, or ask for the wrongT. Only the bridge macro calls it, always with a descriptor C++ just built from a realkj::Promise<T>, and that call already sits inside the macro'sunsafeblock.new_callbacks_promise_futureis now anunsafe fnwith its contract documented: the node is uniquely owned and the callback is the one C++ made for it, producing aT.No bridge or generated code changes. This adds
//src/rust/cxx/kj-rs/compile-testswith a snippet checking that the call needsunsafe; the kj-rs promise tests cover the generated path.