sourcemap: make ParseResult a Result alias (fixes clippy on main) - #38272
dylan-conway wants to merge 1 commit into
Conversation
…variant After #38263 shrank ParseResultFail to 8 bytes, the hand-rolled `enum ParseResult { Fail, Success(ParsedSourceMap) }` (152-byte Success) trips clippy::large_enum_variant, which CI denies. The enum was only ever constructed and immediately matched like a Result, so define it as `Result<ParsedSourceMap, ParseResultFail>` and use Ok/Err at the four call sites.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (5)
WalkthroughThe sourcemap parser now exposes a standard ChangesSourcemap Result migration
Possibly related PRs
Suggested reviewers: Mergeability Score: ⚪ Minimal · up to This localized change replaces the sourcemap parser result with a standard Result while preserving reported success and error behavior; no actionable merge-blocking risk remains beyond normal checks and review. 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
Comment |
There was a problem hiding this comment.
LGTM — mechanical enum→Result alias swap to unblock clippy on main; the inline finding is a comment-only nit.
Extended reasoning...
Overview
Replaces the two-variant ParseResult enum with pub type ParseResult = Result<ParsedSourceMap, ParseResultFail> and mechanically renames Fail/Success to Err/Ok at the four sites that construct or match it: mapping::parse (13 return sites), parse_json in lib.rs (now uses .map_err(|fail| fail.err)?), JSSourceMap::constructor, and SourceMapStore::get_parsed_source_map. One doc-comment reference updated in error.rs.
Security risks
None. No input handling, allocation, or control-flow changes — purely a type-level rename. The .map_err(...)? rewrite in parse_json is behaviorally identical to the deleted match (returns Err(fail.err) on failure, binds the success value otherwise).
Level of scrutiny
Low. This is a lint-fix refactor with no intended behavior change; every hunk is a 1:1 variant rename. I checked that the crate-local Result<T, E = Error> alias re-exported into lib.rs still resolves correctly with an explicit second type parameter (it does — Result<ParsedSourceMap, ParseResultFail> overrides the default E). The dropped ParseResult import in JSSourceMap.rs is dead after the match arms switched to Ok/Err.
Other factors
The one finding (three stale ParseResult::Fail references remaining in a C++ comment and two test descriptions) is comment-only and doesn't affect behavior. Author verified bun run rust:clippy is clean and runtime behavior of node:module SourceMap (valid mappings, malformed mappings, inline-sourcemap error) matches bun 1.4.0. Given this unblocks CI for all other PRs and is a pure mechanical rename, approving.
|
|
||
| impl Error { | ||
| /// What `ParseResult::Fail` reports to the user. | ||
| /// What `ParseResultFail` reports to the user. |
There was a problem hiding this comment.
🟡 This doc-comment update from ParseResult::Fail → ParseResultFail missed three sibling references: src/jsc/bindings/highway_sourcemap.cpp:918 and test/js/node/module/sourcemap-simd.test.ts:447,462 still say ParseResult::Fail. Comment-only, no behavior impact — but per REVIEW.md "grep for every sibling site sharing the pattern", these should be updated in the same PR.
Extended reasoning...
What the bug is
This PR replaces enum ParseResult { Fail(ParseResultFail), Success(ParsedSourceMap) } with pub type ParseResult = Result<ParsedSourceMap, ParseResultFail>, so the ParseResult::Fail variant no longer exists. The PR correctly updated the doc comment at src/sourcemap/error.rs:40 from ParseResult::Fail to ParseResultFail to reflect this, but missed three other comments in the repo that still reference the deleted variant.
The specific stale sites
A repo-wide grep for ParseResult::Fail after this PR shows:
src/jsc/bindings/highway_sourcemap.cpp:918—// and reports the exact same ParseResult::Fail as before.test/js/node/module/sourcemap-simd.test.ts:447—// Scalar caps at 8 bytes and returns no-progress -> ParseResult::Fail;test/js/node/module/sourcemap-simd.test.ts:462—test("out-of-range source index: identical ParseResult::Fail", ...)
These are the only remaining hits; the PR updated all Rust match arms and the error.rs doc comment but did not sweep C++ comments or test descriptions.
Why existing checks don't catch this
These are all inside comments (or a test title string), so neither rustc, clang, nor clippy sees them. The PR's stated verification (bun run rust:clippy + runtime smoke tests) exercises none of them.
Why this is worth fixing
REVIEW.md, under Correctness: the bug class, not the bug → "Fix the whole class in the same PR — grep for every sibling site sharing the pattern" and "Signature changes and renames → grep the whole repo". The PR explicitly recognized this class by editing error.rs:40, so the three remaining sites are same-class stragglers. Left as-is, a future reader grepping for ParseResult::Fail (from these comments) will find no such symbol.
Step-by-step proof
- Before this PR,
ParseResult::Failis a real enum variant (src/sourcemap/lib.rs:108in the base). - This PR deletes it:
-pub enum ParseResult { Fail(...), Success(...) }/+pub type ParseResult = Result<...>. - This PR updates one comment referencing it:
error.rs:40ParseResult::Fail→ParseResultFail. rg 'ParseResult::Fail'on the post-PR tree still returns 3 hits (listed above) — none of them in Rust, so they were missed by the mechanicalFail(→Err(/Success(→Ok(sweep.
How to fix
Update the three comments to say ParseResultFail (or Err(ParseResultFail) where the phrasing describes the return value), matching the change already made at error.rs:40. Zero behavior impact.
|
Ooops, sorry just also fixed in #38280 |
What does this PR do?
cargo clippyhas been red on main since #38263: that change shrankParseResultFailto 8 bytes, sobun_sourcemap::ParseResult { Fail(ParseResultFail), Success(ParsedSourceMap) }(152-byteSuccess) now tripsclippy::large_enum_variant, which the clippy workflow denies. Every PR checked against current main inherits the failure.ParseResultwas only ever built and immediately matched like aResult, so this defines it aspub type ParseResult = Result<ParsedSourceMap, ParseResultFail>;and switches the four call sites (mapping::parse,parse_json, thenode:moduleSourceMapconstructor, and the dev server'sSourceMapStore) toOk/Err. No boxing or#[allow];parse_jsongets to use?. No behavior change intended.How did you verify your code works?
bun run rust:clippy(the CI command, withbuild/debug/codegengenerated) → 0 warnings, 0 errors across the workspace.new (require("node:module").SourceMap)(...)with valid mappings (findEntryresult) and with malformed mappings (SyntaxError: Invalid source index delta at 1), plus an error thrown from abun build --sourcemap=inlineoutput file — all three produce output identical to bun 1.4.0.