Skip to content

Remove dead code: six trait impls nothing uses - #44696

Closed
robobun wants to merge 1 commit into
mainfrom
robobun/0ef3f53a/dead-code-sweep
Closed

robobun wants to merge 1 commit into
mainfrom
robobun/0ef3f53a/dead-code-sweep

Conversation

@robobun

@robobun robobun commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator

Behaviour change: none

Problem

  • Six trait impls in four files have no user. No call reaches them and no bound needs them.
  • rustc's dead_code lint does not report a trait impl, so the workspace's deny lints do not catch them.

Fix

  • Delete the six impls: 49 lines removed, none added. The Notes list them.
  • A use of a removed impl does not compile: each trait is reached through a bound or a path call.
  • Verified: bun bd, cargo check --workspace for the 12 CI targets, nine more checks in three other build configurations, cargo fmt --check, and 12 test files of the touched areas.
  • Self-reviewed: the candidate list had 57 unused items. 51 were cut for the reasons in the Notes.

Background

Downsides

  • None found. Checked: no open PR uses one of the six impls (the Rust lines that each of the 5,822 open PRs adds), and no open PR gets a new merge conflict (merge simulation of the 52 that touch these files).
Notes

Removed impls

  • src/css/generics.rs: impl CssEql for (), impl<T: Parse> Parse for Box<T>, impl<T: Parse> ParseWithOptions for Box<T>. The DeepClone, CssEql, CssHash, IsCompatible and ToCss impls for Box<T> stay: they have users.
  • src/jsc/JSPropertyIterator.rs: impl IntoIterObject for &mut JSObject. The doc of the trait names *mut JSObject and &JSObject as the accepted arguments, and both stay.
  • src/sql_jsc/mysql/protocol/any_mysql_error_jsc.rs: impl MaybeBytes for String. The callers of mysql_error_to_js pass &str, &[u8], &[u8; N], Vec<u8> or an Option of those.
  • src/sql_jsc/postgres/PostgresSQLConnection.rs: impl jsc::JsClass for PostgresSQLConnection. The connection code calls the generated js::to_js directly. Nothing asks for PostgresSQLConnection: JsClass.

Verification

The base moved while this was checked, so each line names its base. The diff is the same 49 lines on each base.

  • On main at bbdc5a5. That is one commit before this PR's base, and that commit only touches bun check:
    • bun bd builds and links (debug, ASAN).
    • cargo check --workspace --keep-going --target <t> passes for the 12 targets of bun run rust:check-all. linux-x64, windows-x64 and darwin-arm64 also pass with --all-targets.
    • linux-x64, windows-x64 and darwin-arm64 pass in three more configurations: --cfg bun_debug --cfg bun_asan --cfg socket_fault_injection, then --release --cfg bun_codegen_embed, then --release --cfg bun_codegen_embed --cfg bun_asan --cfg socket_fault_injection -C debug-assertions=on.
    • cargo fmt --all -- --check is clean.
    • Tests with the debug build: css.test.ts, color.test.ts, nested-selector-expansion.test.ts, sql-connect-error-reporting.test.ts, postgres-row-decode-error.test.ts, postgres-error-then-datarow.test.ts, sql-mysql-bind-oob.test.ts, sql-mysql.test.ts, sql.test.ts, yaml.test.ts, inspect.test.js and parse_args/default-args.test.mjs.
    • Three of those tests need more than the default 5 s on the 12-core machine with the debug build: two in nested-selector-expansion.test.ts and "handles stack overflow protection" in yaml.test.ts. They pass with --timeout 120000. On a faster machine they passed with the default timeout and this same diff.
  • On this PR's base (bd599f5): linux-x64, windows-x64 and darwin-arm64 pass again in the debug + ASAN configuration and in the release configuration.
  • On an earlier base (faac63e): all 12 targets in all four configurations (48 checks).

Why the release configuration is in the loop

cargo check in the dev profile does not set bun_codegen_embed. A first pass deleted bun_zstd::inflate_embedded, which only the release arm of embed_compressed! calls. The release check put it back.

Found unused and left in place (51 of 57)

  • 9 hand-written Debug impls. They are a debugging aid.
  • 21 std-style impls on shared types: Deref, AsRef, Borrow, PartialEq<[u8]>, From, IntoIterator and Display on Interned, ZStr, StoreStr, StoreSlice, RawSlice, ArenaString, BoundedArrayAligned, Utf8Bytes, StringHashMapKey, SmallList, HashMap, JsCell, IndexSet and GenericIndex. Remove dead code: 49 trait impls nothing uses, across 12 crates #43664 left this group to a maintainer decision, and open PRs use some of them.
  • 15 impls that docs or comments name as part of a design: IntoLogWrite for &mut W, ThrowFmtArgs for fmt::Arguments, PoolStorage for UnwiredStorage, StringBuilder for semver_string::Builder, fmt::Write for FmtAdapter, AsFd for &File, the css blanket impls for Option<T>, Size2D, Rect, slices and strings, and IntoHostConstructReturn for Box<T> (a comment in host_fn.rs names Box<T> as a constructor return type).
  • 3 impls on widely used parameters: IntoText for String, IntoText for Box<[u8]> (Log::add_error) and AsFd for &Fd (the syscall wrappers). A new caller can need one at any time.
  • 2 functions that a generator template names: host_fn_setter and host_fn_this_value in src/jsc/host_fn.rs. No generated class calls them today. generate-classes.ts emits the call for a class without sharedThis that has a setter or a passThis method.
  • bun_core::strings::split_once: unused, but clippy.toml names it as the replacement for str::split_once.

Not counted in the 57:

Method

  • Link: the debug link command from build.ninja plus -Wl,--gc-sections, with one --undefined= per #[no_mangle] Rust symbol (3,690). A function that lldb or C++ can call stays a root, and so does what it reaches.
  • Liveness: the line table of that binary (llvm-dwarfdump --debug-line). A fn or an impl block with no live address in its line range is a candidate. This also finds a generic fn that is never instantiated. 3,029 of 31,977 Rust fns had no live code on linux-x64. Most are gated by cfg, are tests, or run at compile time only.
  • Restore loop: delete all candidates, run cargo check --workspace --keep-going, put back each item that an error names, repeat until clean. Targets: the 12 of rust:check-all. Configurations: the four above.
  • A method with a self receiver is not a candidate. A deleted WStr::len fell through Deref to the slice len and still compiled. The six impls here cannot do that: a missing impl fails the bound.
  • Open PRs: main has no merge queue, so a green PR that uses a removed impl breaks main when it merges. The scan reads the Rust lines that each open PR adds against its merge base. It looks for the traits, the types and the call sites: mysql_error_to_js, MaybeBytes, IntoIterObject, a &mut JSObject type, JsClass with PostgresSQLConnection, and Box< or () in src/css. Each hit was read. None passes a String to mysql_error_to_js, and none adds a &mut JSObject.

Other scans in this run, clean or already claimed

  • Names with no reference (Rust, C++, TS), .rs files outside every mod tree, headers that nothing includes, C and C++ sources outside the build, #if 0 and if (false) blocks, commented-out code in C++ and TS, tsc --noUnusedLocals on src/js, and unused Cargo dependencies.
  • Linker-dropped C and C++ functions in src/jsc/bindings and packages/bun-usockets: 77 extern functions have no caller on linux. An open PR already deletes 67 of them. The other ten have a caller on another target, sit in a macro list, or belong to a generic arm.

Remove six hand-written trait impls that have no user. No call and no
bound needs them.

- bun_css: CssEql for (), Parse for Box<T>, ParseWithOptions for Box<T>
- bun_jsc: IntoIterObject for &mut JSObject
- bun_sql_jsc: MaybeBytes for String, JsClass for PostgresSQLConnection

The workspace compiles without them for the 12 CI targets in four
build configurations.
@coderabbitai

coderabbitai Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: oven-sh/bun/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Essentials
  • Run ID: caee6651-f4b6-4e53-b429-ea22214109b1
📥 Commits

Reviewing files that changed from the base of the PR and between bd599f5 and 0ba6f5f.

📒 Files selected for processing (4)
  • src/css/generics.rs
  • src/jsc/JSPropertyIterator.rs
  • src/sql_jsc/mysql/protocol/any_mysql_error_jsc.rs
  • src/sql_jsc/postgres/PostgresSQLConnection.rs
💤 Files with no reviewable changes (4)
  • src/jsc/JSPropertyIterator.rs
  • src/sql_jsc/postgres/PostgresSQLConnection.rs
  • src/css/generics.rs
  • src/sql_jsc/mysql/protocol/any_mysql_error_jsc.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.


Walkthrough

This pull request removes several Rust trait implementations, including CSS parsing and equality support, JavaScript property iterator conversion, MySQL message conversion, and PostgreSQL JavaScript class conversion methods.

Changes

CSS trait implementations

Layer / File(s) Summary
Remove CSS trait implementations
src/css/generics.rs
Removes CssEql for () and Parse and ParseWithOptions for Box<T>.

JavaScript property iteration

Layer / File(s) Summary
Remove mutable-reference conversion
src/jsc/JSPropertyIterator.rs
Removes IntoIterObject for &mut JSObject; support for other listed input types remains.

MySQL error messages

Layer / File(s) Summary
Remove String message support
src/sql_jsc/mysql/protocol/any_mysql_error_jsc.rs
Removes MaybeBytes for String.

PostgreSQL JavaScript class

Layer / File(s) Summary
Remove local JsClass implementation
src/sql_jsc/postgres/PostgresSQLConnection.rs
Removes the local jsc::JsClass implementation and its conversion and constructor methods.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to 0ba6f

No merge-blocking behavior change is identified. The PR is mergeable after normal checks.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the removal of six unused trait implementations, which is the main change.
Description check ✅ Passed The description explains the changes and their rationale, and reports verification results. It covers both required template topics, although it uses different headings.
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.
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@robobun

robobun commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator Author

Status: ready for review.

  • The diff removes six trait impls (49 lines). No call reaches them and no bound needs them.
  • Verified with bun bd, cargo check --workspace for the 12 CI targets, nine more checks in three other build configurations, and 12 test files of the touched areas. The PR body has the commands and the base commits.
  • No open PR uses one of the six impls, and no open PR gets a new merge conflict.

@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.

Code review found no issues

No high-confidence issues detected in this change.

@robobun

robobun commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator Author

Closing as stale: this PR conflicts with main, and its last commit is from 2026-10-07.

The branch stays, so the work is not lost. To pick it up again, rebase the branch on main and reopen this PR.

@robobun robobun closed this Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants