clippy: 33 deny lints + fix 2735 violations across workspace
Adds 45 deny-level clippy lints + dead_code/unused_*/unreachable_* to [workspace.lints], a clippy.toml routing std::{fs,sync,collections,process,env} and println!/eprintln! through bun_* wrappers, and fixes the resulting violations across the workspace. Net −6.2K LOC of dead code.
Lint set
Soundness / leak prevention — undocumented_unsafe_blocks, not_unsafe_ptr_arg_deref, mem_forget, cast_ptr_alignment, transmute_ptr_to_ptr, as_ptr_cast_mut, drop_non_drop, uninit_vec
Performance — redundant_clone, unnecessary_to_owned, needless_collect, or_fun_call, assigning_clones, implicit_clone, iter_overeager_cloned, map_clone, trivially_copy_pass_by_ref, large_types_passed_by_value, large_enum_variant, large_stack_frames, vec_init_then_push, format_collect, manual_memcpy, needless_pass_by_value
Clarity — unnecessary_unwrap, derive_partial_eq_without_eq, derivable_impls, clone_on_ref_ptr, if_same_then_else, todo, unimplemented, dbg_macro, clone_on_copy, useless_conversion, manual_swap, mem_replace_option_with_none, redundant_locals, manual_c_str_literals, precedence, implicit_saturating_sub, ptr_eq
Disallowed — disallowed_{methods,types,macros} configured in clippy.toml: std::sync::{Mutex,RwLock} + parking_lot::* → bun_threading; std::fs::* → bun_sys; std::collections::Hash{Map,Set} → bun_collections (wyhash); std::process::Command → bun_sys::process; println!/eprintln! → bun_core::output; std::env::var → bun_core::env; std::thread::spawn → bun_threading; std::mem::zeroed banned.
rustc — dead_code, unused_imports, unused_variables, unused_mut, unused_assignments, unused_macros, unreachable_code, unreachable_patterns denied workspace-wide. ~505 inline #[allow(unused/dead_code/unreachable_*)] attrs and ~90 crate-level #![allow(unused, ...)] words removed; the items they were hiding deleted or #[cfg]'d to the platform/profile they're live on.
31 default-warn lints explicitly allow'd (Zig-port style).
Notable fixes
- 1,341
// SAFETY:comments added immediately aboveunsafe {blocks, each stating the actual invariant. - 156
not_unsafe_ptr_arg_deref: safefn(p: *mut T)that derefp→unsafe fnwith# Safetydoc, or param changed toNonNull<T>/&T.generate-host-exports.tsalready detectedpub unsafe fnand wraps the thunk body — regenerated. - 47
mem_forget→ManuallyDrop/Box::into_raw/Arc::into_raw/Box::leak.enum_map!(8 sites) replaced withEnumMap::from_fn. - 840 signature changes (
trivially_copy_pass_by_ref+needless_pass_by_value+large_types_passed_by_value):&Copy→Copy, owned-but-only-read →&T. All callers updated. protocol::IsCompatible+calc_protocol_forwarders!:Browsers→&Browsers.SinkHandler/JsSinkType/impl_sink_handler!/VTable:data: StreamResult→&StreamResult.ParserLike::log(&self) -> &mut Log(mut_from_ref): replaced trait method withlog_ptr(&self) -> NonNull<Log>.tick_while_paused:&mut bool→*const bool+read_volatile()— C++ writes through an aliased pointer duringtick(), so&mutwas an aliasing violation, not just a lint.flush_category!(css border): 152KB stack frame →#[inline(never)]helpers.cppbind.ts:&x as *const T→core::ptr::from_ref;// SAFETY:above generatedunsafe { raw::… }calls.- Dead-code deletions: ~650 lines of duplicate draft
unicode.rsimpls; ~500 lines of unusedresolver/fs.rstypes; ~250 linesshell_parser; ~180 linespackage_jsonreverse-resolution; 256-line deadname_static; dead FFI extern decls (Rust→C++ imports nothing calls). - Platform/profile cfg-gating: ~60 files where an item is live only on one target/profile (
#[cfg(target_os = ...)]/#[cfg(debug_assertions)]).
CI
.github/workflows/clippy.yml—bun run rust:clippywith inline PR annotations via.github/rust-matcher.json..github/workflows/miri.yml—bun run rust:miri(Tree Borrows) on the FFI-free crate set.
Exceptions (the only #![allow]s added)
- 4×
build.rs:disallowed_{methods,types,macros}— build scripts run on the host beforebun_*crates exist. bun_alloc/lib.rs:disallowed_types— T0 foundation crate;bun_threading/bun_collectionsdepend on it.#[allow]insidemacro_rules!/quote!{}bodies are preserved — they suppress lints in emitted code that varies per call site.
cargo clippy --workspace --no-deps: 0 errors. bun run rust:check-all: 10/10. bun bd: builds.