Repository navigation
napi: add the missing safety comment on free_orphaned's unsafe block - #34125
cirospaciari wants to merge 1 commit into
Conversation
`cargo clippy` fails on main, and so on every open pull request that touches a
.rs file:
error: unsafe block missing a safety comment
--> src/runtime/napi/napi_body.rs:2811:14
error: could not compile `bun_runtime` (lib) due to 1 previous error
`undocumented_unsafe_blocks` is denied workspace-wide. #34067 added
`free_orphaned`, whose doc comment carries a `SAFETY:` paragraph for the
function's own contract, but the lint wants a comment on the unsafe *block*.
Its sibling `free` ten lines up already has exactly the one this needs.
The Clippy workflow has no `push:` trigger, so main never lints itself and
this only surfaces on contributors' PRs, attributed to their commits.
|
Updated 3:33 AM PT - Jul 14th, 2026
✅ @cirospaciari, your commit 1afd910a71efd84702d4592b624cfbdf51b205a7 passed in 🧪 To try this PR locally: bunx bun-pr 34125That installs a local version of the PR into your bun-34125 --bun |
WalkthroughA safety comment was added to ChangesThread-safe function cleanup
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/runtime/napi/napi_body.rs`:
- Line 2811: Update the SAFETY comment in ThreadSafeFunction::new to state that
the pointer originates from bun_core::heap::into_raw(Box::new(init)), while
preserving the note that heap::take is valid for reclaiming it.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: b4a8cdd1-5abc-46ea-95e1-8edc63093ef5
📒 Files selected for processing (1)
src/runtime/napi/napi_body.rs
| /// SAFETY: `this` is a live allocation from `new`, the caller holds no | ||
| /// lock on it, and no other thread holds a reference. | ||
| unsafe fn free_orphaned(this: *mut ThreadSafeFunction) { | ||
| // SAFETY: `this` was allocated by heap::alloc in `new`. |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Document the actual allocation path.
ThreadSafeFunction::new uses bun_core::heap::into_raw(Box::new(init)) at Line 2473, not heap::alloc. heap::take is still valid for this pointer, but this SAFETY comment should accurately describe the provenance.
Proposed fix
- // SAFETY: `this` was allocated by heap::alloc in `new`.
+ // SAFETY: `this` was allocated by `heap::into_raw(Box::new(init))` in `new`.📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // SAFETY: `this` was allocated by heap::alloc in `new`. | |
| // SAFETY: `this` was allocated by `heap::into_raw(Box::new(init))` in `new`. |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/runtime/napi/napi_body.rs` at line 2811, Update the SAFETY comment in
ThreadSafeFunction::new to state that the pointer originates from
bun_core::heap::into_raw(Box::new(init)), while preserving the note that
heap::take is valid for reclaiming it.
There was a problem hiding this comment.
LGTM — comment-only clippy fix.
What was reviewed:
- Verified the added
// SAFETY:comment onfree_orphaned's unsafe block is verbatim identical to the sibling atnapi_body.rs:2800(free), which wraps the samebun_core::heap::take(this)call. - Confirmed no code changes — the
drop(unsafe { ... })line itself is untouched; only the comment line is inserted.
Extended reasoning...
Overview
This PR adds a single // SAFETY: comment above the unsafe { bun_core::heap::take(this) } block inside ThreadSafeFunction::free_orphaned in src/runtime/napi/napi_body.rs. The workspace has clippy::undocumented_unsafe_blocks = "deny", and #34067 introduced this function with a doc-comment SAFETY paragraph on the function but no comment on the inner block, breaking clippy on main. The added comment is copied verbatim from the sibling free function ten lines above (line 2800), which wraps an identical heap::take call.
Security risks
None. This is a comment-only change with zero effect on generated code or runtime behavior.
Level of scrutiny
Minimal. This is the canonical trivial-approve case: a one-line comment addition to satisfy a lint, matching an existing adjacent pattern exactly. The PR description documents reproduction on clean main, verification that clippy passes on three targets after the fix, and cargo fmt --check cleanliness.
Other factors
- No prior reviews or outstanding comments on the PR (only the robobun build notification).
- The bug hunting system found no issues.
- I verified in the current tree that both the sibling comment at line 2800 and the new comment at line 2811 are present and identical, and that the
drop(unsafe { ... })line was not modified. - The PR description's suggestion about adding a
push:trigger to the clippy workflow is explicitly out of scope for this PR ("Happy to send that separately"), so there's nothing else to review here.
|
Superseded — The underlying issue stands though: this is the third clippy break to reach |
cargo clippyis failing onmainagain, and therefore on every open pull request that touches a.rsfile:undocumented_unsafe_blocks = "deny"is set workspace-wide. #34067 addedThreadSafeFunction::free_orphaned, whose doc comment carries aSAFETY:paragraph describing the function's own contract — but the lint wants a comment attached to the unsafe block. Its siblingfree, ten lines above, already has exactly the comment this one needs:Why it keeps happening
.github/workflows/clippy.ymltriggers onworkflow_call,workflow_dispatch,pull_requestandmerge_group— there is nopush:trigger, so main never lints itself. Sincepull_requestlints the PR merged into main, breaks introduced on main surface on contributors' PRs and look like their fault.This is the third such breakage in a few days (#33951 fixed
let_and_returninbun_pathsandlarge_stack_framesinbun_runtime; #33958 fixed the aarch64/macOS-only lints). Adding apush:trigger — or a scheduled run on main — would catch these at the source. Happy to send that separately if wanted.Verification
maintip (16c557635b) before changing anything;cargo clippy -p bun_runtime --no-depsreports the error, and reverting the one-line fix reproduces it again (2 errors → 0).cargo clippy --workspace --no-deps --keep-goingexits 0 on all three: macOS arm64 (host),x86_64-unknown-linux-gnu(what the Clippy workflow runs), andaarch64-unknown-linux-gnu.cargo fmt --check -p bun_runtimeclean.Comment-only; no runtime surface.