Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/react_compiler/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
clippy::disallowed_types,
clippy::disallowed_methods,
unreachable_pub,
dead_code,
reason = "ported from facebook/react react_compiler_hir; uses std collections by design"
)]
#![allow(
Expand Down
2 changes: 0 additions & 2 deletions src/runtime/api/bun/h2/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
//! §4.2/§6 validation. Connection-level framing lives here; stream-level (HEADERS/DATA/RST) and the
//! outbound request/respond paths build on top of this.

#![allow(dead_code)]

use super::flow_control::{RecvWindow, SendWindow};
use super::hpack;
use super::settings::{self, Settings};
Expand Down
2 changes: 0 additions & 2 deletions src/runtime/api/bun/h2/flow_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
//! * Recv window — how much DATA the peer may still send us; replenished by emitting
//! WINDOW_UPDATE once enough has been consumed.

#![allow(dead_code)]

use super::wire::{DEFAULT_WINDOW_SIZE, ErrorCode, MAX_WINDOW_SIZE};

/// Outbound (send) window. Signed because a SETTINGS-driven INITIAL_WINDOW_SIZE decrease can push
Expand Down
2 changes: 0 additions & 2 deletions src/runtime/api/bun/h2/hpack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
//! lockstep. Decode results alias a shared buffer and MUST be copied before the next call
//! (see lshpack.rs).

#![allow(dead_code)]

use bun_http::lshpack::{DecodeResult, HpackError, HpackHandle};

/// RFC 7541 §6.3: a Dynamic Table Size Update integer never needs more than 6 bytes for a u32.
Expand Down
2 changes: 0 additions & 2 deletions src/runtime/api/bun/h2/settings.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
//! HTTP/2 SETTINGS (RFC 9113 §6.5). Pure: value semantics, range validation, on-wire packing,
//! and the INITIAL_WINDOW_SIZE retroactive-window delta. Part of the from-scratch rewrite.

#![allow(dead_code)]

use super::wire::{self, ErrorCode, SettingId};

/// Logical SETTINGS values. Defaults match Node v27 `getDefaultSettings()` exactly
Expand Down
2 changes: 0 additions & 2 deletions src/runtime/api/bun/h2/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
//! as the stream `state`): IDLE=1, OPEN=2, RESERVED_LOCAL=3, RESERVED_REMOTE=4,
//! HALF_CLOSED_LOCAL=5, HALF_CLOSED_REMOTE=6, CLOSED=7.

#![allow(dead_code)]

#[derive(Clone, Copy, PartialEq, Eq, Debug)]
#[repr(u8)]
pub enum State {
Expand Down
2 changes: 0 additions & 2 deletions src/runtime/api/bun/h2/wire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
//! This is part of the from-scratch rewrite of `node:http2` (replacing the ported
//! `h2_frame_parser.rs`). Spec section numbers reference RFC 9113 unless noted.

#![allow(dead_code)]

/// RFC 9113 §3.4: the 24-octet client connection preface.
pub const CONNECTION_PREFACE: &[u8] = b"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n";

Expand Down
25 changes: 23 additions & 2 deletions test/internal/source-lints/dead-code-escapes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,23 @@ import { globAllSources } from "../../../scripts/glob-sources.ts";
// after the allow, e.g. `#[cfg_attr(test, allow(dead_code), derive(Debug))]`
// (`[^\]]*\]` tail). Neither `[^\]]` class can cross a `]`, so a match is always
// fenced inside a single attribute and cannot span from one `#[...]` to the next.
// Module-level `#![allow(...)]` blocks (codegen surfaces such as
// `runtime/generated_classes.rs` and `jsc/cpp.rs`) are intentionally not counted.
// Module-level `#![allow(...)]` blocks are not part of this inventory; see
// `MODULE_ESCAPE` below.
const ESCAPE = /#\[\s*(?:cfg_attr\([^\]]+?,\s*)?allow\([^)]*\bdead_code\b[^)]*\)[^\]]*\]/g;

// A module-level `#![allow(dead_code)]` hides a whole file from rustc, and the
// cross-crate hawk analysis treats every item under it as a reachability root.
const MODULE_ESCAPE = /#!\[\s*(?:cfg_attr\([^\]]+?,\s*)?allow\([^\]]*?(?<![\w:])dead_code\b[^\]]*\]/;
const MODULE_ESCAPE_ALLOWED = new Set([
// Generated extern surfaces: most declarations are unused by design.
"src/jsc/cpp.rs",
"src/runtime/generated_classes.rs",
// Shares files with bun_install; each of the two builds uses a different half.
"src/install/windows-shim/main.rs",
// Stale. #40690 removes it together with the items it hides.
"src/react_compiler/diagnostics/mod.rs",
]);

const limits: Record<string, number> = await Bun.file(import.meta.dir + "/dead-code-escape-limits.json").json();

const root = path.resolve(import.meta.dir, "..", "..", "..");
Expand All @@ -55,6 +68,7 @@ const tracked: Set<string> | null = (() => {
})();

const counts: Record<string, number> = {};
const moduleLevel: string[] = [];
for (const abs of rustSources) {
const source = path.relative(root, abs).replaceAll(path.sep, "/");
// `src/cli` is a symlink into `src/runtime/cli`; count each file once
Expand All @@ -67,6 +81,7 @@ for (const abs of rustSources) {
const stripped = content.replace(/^\s*\/\/.*$/gm, "");
const n = [...stripped.matchAll(ESCAPE)].length;
if (n > 0) counts[source] = n;
if (MODULE_ESCAPE.test(stripped)) moduleLevel.push(source);
}

if (typeof describe === "undefined") {
Expand Down Expand Up @@ -100,3 +115,9 @@ describe("#[allow(dead_code)] escapes", () => {
});
}
});

describe("module-level #![allow(dead_code)] escapes", () => {
test("the files that opt out wholesale are exactly MODULE_ESCAPE_ALLOWED", () => {
expect(moduleLevel.toSorted()).toEqual([...MODULE_ESCAPE_ALLOWED].toSorted());
});
});
Loading