Skip to content

Remove dead code: 8 trait impls nothing uses, in bun_bundler, bun_core and bun_css - #45988

Open
robobun wants to merge 1 commit into
mainfrom
robobun/ee73db60/dead-code-sweep
Open

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

Conversation

@robobun

@robobun robobun commented Oct 18, 2026 •

Copy link
Copy Markdown
Collaborator

Behaviour change: none

Problem

  • Four types have trait impls that no code uses: PartialEq and Eq for StableRef (bun_bundler), and Display and Error for InvalidCharacter (bun_core), ColorError and PrintErr (bun_css).
  • No lint reports an unused trait impl: rustc's dead_code skips impls.

Fix

  • Delete the 8 impls: 30 lines in 4 files.
  • Without them the workspace compiles for all 12 targets, so nothing compares a StableRef with == or formats one of the three errors.
  • Verified on main at ad4089b: bun run rust:check-all, bun run rust:clippy, cargo check --workspace --all-targets, a release-profile check, cargo fmt --all --check, bun bd, and 8 test files (Notes).
  • Self-reviewed: 49 concerns raised, 41 addressed, most by a cut from 57 impls to these 8. Seven are about the sweep process (Notes). Rejected: keep the bun_lint impls here and ask in the body (carved out, as in Remove dead code from bun_sema and bun_format: 6 trait impls nothing uses #45430).

Background

  • Remove dead code: 49 trait impls nothing uses, across 12 crates #43664 removed Ord and PartialOrd for StableRef and From<InvalidCharacter> for CrateError. These impls are what it left beside them.
  • An Error impl goes together with its Display. No merged sweep removed that pair before.
  • main has no merge queue, so an open pull request that uses a removed impl breaks main when it merges. The Rust lines that all 5,936 open pull requests add do not use these impls.

Downsides

  • None found for users. The search of open pull requests is by type name and cannot see a use that does not name the type. Searches for StableRef comparisons, parse_double callers and formatted css errors found none.
Notes

What the search found

  • The search ran on 2026-10-17 in a scratch copy of the tree at b28212a. Hand-written impl Trait for Type blocks became blank lines (3,081 of the 4,812 in the workspace, in two passes). cargo check --workspace ran, and each impl that an error named went back. This repeated until the workspace compiled. The set then went through x86_64-pc-windows-msvc, aarch64-apple-darwin, --all-targets, the debug cfgs, a release-profile check, and --features bun_react_compiler/fixtures.
  • Left out of the search, because a clean compile proves nothing for them: Drop, Deref, DerefMut, Clone, Copy, Send, Sync, Unpin, Debug, Any, Fn*, Future, GlobalAlloc, Allocator, every unsafe impl, blanket impls, impls whose self type derefs or is a reference, a trait implemented for both T and &T, and impls that share a member name with an impl of another trait for the same type.
  • 130 impls survived. Only 8 are in this diff.

The other 122

Functions, types and trait methods

  • A marker probe: #[deprecated(note = "DP:<id>")] on an item in a scratch tree makes rustc report each use site, with no change to name resolution.
  • Every bare pub fn (10,838): 50 have no use on Linux, Windows, macOS, in tests and under the debug cfgs. Open pull requests delete 36 of them. Open pull requests use two more: fs.watch: watch symlink entries of a recursive tree on Linux #43090 calls posix::s_isdir, and Remove libuv on Windows #42819 renames the Windows umask and calls it. The other 12 are named by src/codegen/generate-classes.ts, used only under another cfg or in release builds, gated to FreeBSD or Android, or are small leads (is_not_semicolon_token in bun_lint, the windows_enable_stdio_inheritance declaration in bun_windows_sys).
  • Every bare pub struct, enum, union, type alias, trait, const and static (7,347): 109 have no use outside their own definition and impls. They are constants of FFI tables, items gated to FreeBSD or wasm, and two types that Remove dead code from bun_parsers, bun_core, bun_css, and the base64-js fallback #41004 removes.
  • Every method of a bare pub trait (840): 11 have no caller. Open pull requests delete 9.
  • src/js (216 files) and scripts/ (175 files) were read for unused declarations. Two small leads that no open pull request covers: defaultCwd in src/js/builtins/shell.ts and assertEncodingForWindows in src/js/node/fs.ts are never assigned.

Concerns from the self-review that are not addressed here

  • Seven are about the sweep, not this diff:
    • One pull request that asks the two open questions: do unused std impls on shared cells, index types and containers stay, and do the unused Hash and From impls of the bun_lint handles stay? The 34 impls of the two groups above would go into it.
    • The 44 unused impls in the eight conflicting sweeps do not move while those stay open.
    • A lint for unused trait impls beside mordant's unused_pub would stop the class from growing back.
  • One is rejected: keep the bun_lint impls in this diff and ask at the top of the body. They are carved out instead, as in Remove dead code from bun_sema and bun_format: 6 trait impls nothing uses #45430.

Verification

  • The full set below ran on ad4089b plus this diff. The branch was then rebased onto ea6a2c7 with no conflict. On that base cargo check --workspace, bun run rust:clippy, cargo check --workspace --all-targets and cargo fmt --all --check ran again and pass.
  • bun run rust:check-all: 12 ok, 0 failed, 0 skipped.
  • bun run rust:clippy, cargo check --workspace --all-targets, cargo check --workspace --release with the release codegen and --cfg bun_codegen_embed, cargo fmt --all --check.
  • bun bd, then with the debug build: test/js/bun/css/css.test.ts, color.test.ts, css-loader.test.ts, test/bundler/bundler_banner.test.ts, bundler_splitting.test.ts, test/js/bun/toml/toml.test.ts, test/js/bun/resolve/toml/toml-parse.test.ts, test/js/bun/yaml/yaml-block-scalar-matrix.test.ts. All pass.
  • On an earlier base (017b243) I also ran test/js/bun/css/ as a whole (20 files): 2512 pass, 3 fail. The three are the loops of css-fuzz.test.ts. The test gives each a fixed 10 s limit, and the debug build does not finish them inside it.
  • Open pull requests, scanned again at the rebase: the merge refs of all 5,936 open pull requests, 3,505 of which change Rust lines. None but this one adds or removes an impl for these four types. StableRef occurs in the added lines of 10 (import lists and two comments). InvalidCharacter occurs in 8 (the ParseIntError variant, import lists, comments, and another struct of that name in compile: verify the downloaded target executable against the registry integrity #36173). PrintErr occurs in 27 (import lists, types, and one PrintErr::CSSPrintError). ColorError occurs in none.

@robobun

robobun commented Oct 18, 2026 •

Copy link
Copy Markdown
Collaborator Author
Updated 10:26 AM PT - Oct 20th, 2026

❌ @robobun, your commit ce048b8 has 1 failures in Build #129510 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 45988

That installs a local version of the PR into your bun-45988 executable, so you can run:

bun-45988 --bun

@coderabbitai

coderabbitai Bot commented Oct 18, 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: Advanced
  • Run ID: 2f54ce2d-ca4c-4117-8be2-c873014a0e12
📥 Commits

Reviewing files that changed from the base of the PR and between 4701048 and ce048b8.

📒 Files selected for processing: 2
  • src/bundler/bundle_v2.rs
  • src/css/css_parser.rs
💤 Files with no reviewable changes: 2
  • src/bundler/bundle_v2.rs
  • src/css/css_parser.rs

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

Walkthrough

The changes remove Display and core::error::Error implementations from InvalidCharacter, ColorError, and PrintErr. They also remove PartialEq and Eq implementations from StableRef.

Changes

Trait Implementation Removals

Layer / File(s) Summary
Remove error formatting implementations
src/bun_core/fmt.rs, src/css/css_parser.rs, src/css/lib.rs
InvalidCharacter, ColorError, and PrintErr no longer implement Display or core::error::Error.
Remove StableRef equality traits
src/bundler/bundle_v2.rs
StableRef no longer implements PartialEq or Eq.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to ce048

This change deletes unused trait implementations and is not expected to change runtime behavior. Compile checks reported by the author cover remaining uses, so merge risk is minimal.

Pre-merge checks: Passed 4
Check name Status Explanation
Title check Passed The title clearly summarizes the main change: removal of eight unused trait implementations across bun_bundler, bun_core, and bun_css.
Description check Passed The description explains the problem, fix, scope, behavior impact, background, risks, and verification results. It does not use the template headings exactly, but it provides the 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.
Full details: Description check

Explanation

The description explains the problem, fix, scope, behavior impact, background, risks, and verification results. It does not use the template headings exactly, but it provides the required information in equivalent sections.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@robobun

robobun commented Oct 18, 2026 •

Copy link
Copy Markdown
Collaborator Author

Status: ready for review.

How the deletions were verified:

  • Without the 8 impls, bun run rust:check-all passes on 12 of 12 targets, on main at ad4089b. A use of == on a StableRef, or of {} on InvalidCharacter, ColorError or PrintErr, does not compile without the impl.
  • bun run rust:clippy, cargo check --workspace --all-targets, a release-profile check, cargo fmt --all --check and bun bd pass on that base. Eight test files in the touched areas pass with the debug build.
  • The branch is now rebased onto ea6a2c7, with no conflict. On that base cargo check --workspace, bun run rust:clippy, cargo check --workspace --all-targets and cargo fmt --all --check pass again.
  • The Rust lines that all 5,936 open pull requests add do not use these impls, and no other open pull request deletes them.

The first draft of this sweep had 57 impls. A self-review took 49 out: open pull requests use or already delete some, and earlier sweeps set the others aside for a maintainer decision. The pull request body lists each group.

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

Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.

LGTM — pure deletion of eight unused trait impls; a repo-wide search found no == on StableRef and no Display/Error consumer ({} formatting, dyn Error, #[from]) of InvalidCharacter, ColorError or PrintErr, so the removal is behavior-preserving. The inline nit about the matching InvalidDate pair is optional follow-up, not a blocker.

Extended reasoning...

The commit removes 30 lines across src/bun_core/fmt.rs, src/bundler/bundle_v2.rs, src/css/css_parser.rs and src/css/lib.rs, adding nothing; it touches no security-sensitive surface. Grepping src/ shows every parse_double/ColorError/PrintErr consumer only propagates or discards the error (e.g. map_err(|_| ()), Err(_) =>), and the only StableRef consumers call is_less_than in sort comparators that never use equality, which is what decided approve. The changed files have no CODEOWNERS entry and the timeline shows no outstanding reviewer objection. Compilation across targets was not run here; the conclusion rests on the search of callers plus the author's stated rust:check-all run.

Comment thread src/bun_core/fmt.rs
…e and bun_css

Delete four hand-written impl pairs that no code needs:
PartialEq and Eq for StableRef, and Display and Error for
InvalidCharacter, ColorError and PrintErr.

The workspace compiles for every target without them.
@robobun
robobun force-pushed the robobun/ee73db60/dead-code-sweep branch from 4701048 to ce048b8 Compare October 20, 2026 11:49

This branch has not been deployed

No deployments
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