Skip to content

clippy: fix the remaining lints on aarch64-linux and macOS - #33958

Merged
Jarred-Sumner merged 1 commit into
mainfrom
ciro/clippy-aarch64-macos
Jul 11, 2026
Merged

Jarred-Sumner merged 1 commit into
mainfrom
ciro/clippy-aarch64-macos

Conversation

@cirospaciari

Copy link
Copy Markdown
Member

Follow-up to #33951, which unbroke cargo clippy on the Clippy workflow's runner (x86_64-unknown-linux-gnu). The workspace is still not clean on the other hosts, so bun run rust:clippy fails for anyone developing on an Apple Silicon Mac, and for the aarch64 Linux target.

Measured on main (55ba6e453c) vs this branch, cargo clippy --workspace --no-deps --keep-going:

macOS arm64 (host) aarch64-unknown-linux-gnu x86_64-unknown-linux-gnu
main ❌ 2 errors ❌ 2 errors ✅
this PR ✅ ✅ ✅

ptr_cast_constness — aarch64 only

c_char is u8 on aarch64 and i8 on x86_64, so these casts change only constness on aarch64 and the lint fires there but not on the runner:

  • bun_core::util::dupe_z — p as *const c_char
  • bun_alloc::free_sensitive_cstr — p as *mut u8, p as *mut c_void

Rewritten with .cast() / .cast_const() / .cast_mut(). These are not "smarter" than as: in core they are literally #[inline(always)] pub const fn cast_const(self) -> *const T { self as _ }, so each rewrite is the same single PtrToPtr cast with the same address and the same provenance.

The *const → *mut laundering in free_sensitive_cstr is pre-existing and unchanged by this PR. The pointer's root is a default_alloc::malloc allocation that dupe_z already wrote through, so writing through it here was sound before and is sound now — Rust does not track mutability in raw-pointer provenance.

derivable_impls — macOS only

Sendfile's Default impl is only derivable where the #[cfg(any(target_os = "linux", target_os = "android"))] fields are absent. On linux/android the impl carries socket_fd: Fd::INVALID, and Fd has no Default impl at all — #[derive(Default)] would not compile there. Suppressed with the reason recorded.

#[allow] rather than #[expect] in both suppression sites, because an expectation would go unfulfilled on the platform where the lint doesn't fire, and warnings = "deny" would turn that into an error.

Verification

cargo clippy --workspace --no-deps --keep-going exits 0 on all three targets above (and cargo fmt --check is clean). Built bun-debug and exercised the touched crates through the CLI — path.resolve/path.win32.normalize, process.env, Bun.spawnSync — plus bun bd test test/js/node/path/ → 122 pass, 0 fail.

Reverting just this commit reproduces both failures on macOS and aarch64, so the changes are load-bearing.

`cargo clippy` passes on x86_64-linux after the previous two commits, but the
workspace is still not clean on the other hosts contributors and CI builds run.

`ptr_cast_constness` on aarch64, where `c_char` is `u8` so these casts change
only constness (on x86_64 `c_char` is `i8`, so the type changes too and the
lint stays quiet):

  - `bun_core::util::dupe_z`           `p as *const c_char`
  - `bun_alloc::free_sensitive_cstr`   `p as *mut u8`, `p as *mut c_void`

Rewritten with `.cast()` / `.cast_const()` / `.cast_mut()`, which are
`#[inline(always)] self as _` in core — the same single `PtrToPtr` cast, same
address, same provenance. The `*const` -> `*mut` laundering in
`free_sensitive_cstr` is pre-existing and unchanged; the pointer's root is a
`default_alloc::malloc` allocation that `dupe_z` already wrote through.

`derivable_impls` on macOS for `Sendfile`: the impl is only derivable where the
linux/android-gated fields are absent, and `Fd` has no `Default` impl, so
`#[derive(Default)]` would not compile there. Suppressed with the reason
recorded; `#[allow]` rather than `#[expect]` since the lint does not fire on
linux.

Verified `cargo clippy --workspace --no-deps --keep-going` exits 0 on all
three: macOS arm64 (host), x86_64-unknown-linux-gnu (what the Clippy workflow
runs), and aarch64-unknown-linux-gnu.
@robobun

robobun commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator
Updated 7:28 PM PT - Jul 10th, 2026

@cirospaciari, your commit cf55bed is building: #71774

@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 4ddb31a5-ef8a-4feb-9273-af10a177d43e

📥 Commits

Reviewing files that changed from the base of the PR and between 55ba6e4 and cf55bed.

📒 Files selected for processing (3)
  • src/bun_alloc/lib.rs
  • src/bun_core/util.rs
  • src/runtime/server/FileResponseStream.rs

Walkthrough

Changes

Pointer and lint updates

Layer / File(s) Summary
Typed pointer conversions
src/bun_alloc/lib.rs, src/bun_core/util.rs
Raw pointer casts in free_sensitive_cstr and dupe_z now use typed conversion methods without changing allocation, copying, zeroing, or freeing behavior.
Sendfile default lint allowance
src/runtime/server/FileResponseStream.rs
Adds a targeted Clippy allowance above the platform-specific Sendfile Default implementation.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the main change: fixing remaining Clippy lints on aarch64 Linux and macOS.
Description check ✅ Passed The description includes the change summary and a detailed verification section, covering the template's required information.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Comment @coderabbitai help to get the list of available commands.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — mechanical clippy fixes with no behavioral change.

What was reviewed:

  • .cast()/.cast_const()/.cast_mut() rewrites in dupe_z and free_sensitive_cstr — same address/mutability/pointee as the original as casts, just split so the constness change is explicit.
  • Confirmed Fd derives no Default (src/bun_core/util.rs:932), so #[derive(Default)] on Sendfile would indeed fail on linux/android; #[allow] over #[expect] is correct given the lint only fires on non-linux targets.
Extended reasoning...

Overview

Three-file follow-up to #33951 fixing target-specific clippy lints: two ptr_cast_constness sites in bun_alloc::free_sensitive_cstr / bun_core::util::dupe_z rewritten from as to .cast() chains, and one #[allow(clippy::derivable_impls, reason = ...)] on Sendfile's manual Default impl in FileResponseStream.rs.

Security risks

None. The pointer casts are byte-for-byte equivalent to the previous as casts (cast/cast_const/cast_mut are #[inline(always)] wrappers around self as _). The *const → *mut laundering in free_sensitive_cstr is pre-existing and its soundness argument (root allocation is a writable default_alloc::malloc block) is unchanged. The Sendfile change is a lint attribute only — the impl body is untouched.

Level of scrutiny

Low. This is lint hygiene with zero runtime semantic change, in the same vein as the immediately preceding #33951. I traced each rewritten cast: dupe_z's p is *mut u8, so p.cast_const().cast::<c_char>() = *const c_char (same as before); free_sensitive_cstr's p is *const c_char, so .cast::<u8>().cast_mut() = *mut u8 and .cast::<c_void>().cast_mut() = *mut c_void (same as before). Verified Fd has no Default impl, making the suppression's stated reason accurate, and the #[allow]-not-#[expect] choice is correct since the lint is absent on linux where warnings = deny would flag an unfulfilled expectation.

Other factors

No CODEOWNERS on the touched paths. No prior review comments. Bug hunter found nothing. The PR description's verification (clippy clean on all three targets, cargo fmt --check, path tests passing) is appropriate for a no-behavior-change lint fix.

@Jarred-Sumner
Jarred-Sumner merged commit 4a690d4 into main Jul 11, 2026
35 of 48 checks passed
@Jarred-Sumner
Jarred-Sumner deleted the ciro/clippy-aarch64-macos branch July 11, 2026 02:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants