Skip to content

chore: enable ref-option* lints#6740

Merged
LesnyRumcajs merged 2 commits intomainfrom
enable-ref-option-lints
Mar 15, 2026
Merged

chore: enable ref-option* lints#6740
LesnyRumcajs merged 2 commits intomainfrom
enable-ref-option-lints

Conversation

@LesnyRumcajs
Copy link
Member

@LesnyRumcajs LesnyRumcajs commented Mar 15, 2026

Summary of changes

Changes introduced in this pull request:

  • Enabled ref_option clippy lints

Reference issue to close (if applicable)

Closes

Other information and links

https://rust-lang.github.io/rust-clippy/rust-1.94.0/index.html#ref_option
https://www.youtube.com/watch?v=6c7pZYP_iIE

Change checklist

  • I have performed a self-review of my own code,
  • I have made corresponding changes to the documentation. All new code adheres to the team's documentation standards,
  • I have added tests that prove my fix is effective or that my feature works (if possible),
  • I have made sure the CHANGELOG is up-to-date. All user-facing changes should be reflected in this document.

Outside contributions

  • I have read and agree to the CONTRIBUTING document.
  • I have read and agree to the AI Policy document. I understand that failure to comply with the guidelines will lead to rejection of the pull request.

Summary by CodeRabbit

  • Refactor

    • Standardized optional-reference handling across the codebase, simplifying internal APIs and updating tests accordingly.
  • Chores

    • Enabled workspace-wide linting configuration to enforce consistent code-quality rules.

@LesnyRumcajs LesnyRumcajs requested a review from a team as a code owner March 15, 2026 10:41
@LesnyRumcajs LesnyRumcajs requested review from akaladarshi and hanabi1224 and removed request for a team March 15, 2026 10:41
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 15, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a838ad80-bbe1-4fe8-9e28-30f6af02d3c5

📥 Commits

Reviewing files that changed from the base of the PR and between a107265 and b2cc0a4.

📒 Files selected for processing (2)
  • src/rpc/methods/eth/filter/mod.rs
  • src/utils/net/download_file.rs

Walkthrough

Replaced multiple occurrences of &Option<T> with Option<&T> for parameters and return types across the codebase and updated all call sites. Added workspace-level lints sections in root and interop-tests Cargo.toml files (duplicate entry present in root).

Changes

Cohort / File(s) Summary
Cargo Configuration
Cargo.toml, interop-tests/Cargo.toml
Added [lints] workspace = true and [workspace.lints.clippy] with ref_option = "deny" and ref_option_ref = "deny"; root Cargo.toml contains a duplicate clippy subsection.
DB CAR implementations
src/db/car/forest.rs, src/db/car/plain.rs, src/db/car/any.rs
Changed metadata() return type from &Option<FilecoinSnapshotMetadata> to Option<&FilecoinSnapshotMetadata> and adjusted internals to return optional references.
DB usage & tests
src/daemon/db_util.rs, src/chain/tests.rs
Updated metadata access: removed redundant .as_ref() chaining and adapted tests to new Option<&...> return shape.
CLI: mpool filtering
src/cli/subcommands/mpool_cmd.rs
filter_messages() now takes to: Option<&StrictAddress> and from: Option<&StrictAddress>; call sites and tests updated to pass .as_ref() where appropriate.
Ethereum tx helpers
src/eth/transaction.rs, src/eth/eip_1559_transaction.rs, src/eth/eip_155_transaction.rs, src/eth/homestead_transaction.rs
Switched format_address() and get_filecoin_method_info() to accept Option<&EthAddress>; updated call sites to use .as_ref() to pass optional references.
RPC: chain selectors
src/rpc/methods/chain.rs, src/rpc/types/tipset_selector.rs
Changed functions (get_tipset_by_anchor, TipsetAnchor::validate) to accept Option<&TipsetAnchor> and updated callers to use .as_ref().
RPC: eth filters & types
src/rpc/methods/eth.rs, src/rpc/methods/eth/filter/mod.rs, src/rpc/methods/eth/types.rs
Adjusted filter-related signatures to accept optional references (e.g., match_filter_criteria, install_filter) and updated call sites to pass .as_ref()/.as_deref().
IPLD tests & small utilities
src/ipld/tests/selector_explore.rs, src/shim/actors/convert.rs, src/utils/net/download_file.rs
Refactored helper/test signatures to accept Option<&T> and adapted internal matching/invocation accordingly.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • akaladarshi
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: enabling ref-option* lints across the codebase with associated refactoring.
Docstring Coverage ✅ Passed Docstring coverage is 82.93% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch enable-ref-option-lints
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch enable-ref-option-lints
📝 Coding Plan
  • Generate coding plan for human review comments

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

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (2)
src/db/car/forest.rs (1)

121-135: Please document the public metadata method.

Line 121 introduces/updates a public API signature but still lacks a doc comment.

💡 Proposed doc comment
+    /// Returns snapshot metadata for v2 snapshots, if present and decodable.
+    ///
+    /// Returns `None` for v1 snapshots or when metadata is unavailable.
     pub fn metadata(&self) -> Option<&FilecoinSnapshotMetadata> {

As per coding guidelines: Document public functions and structs with doc comments.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/db/car/forest.rs` around lines 121 - 135, Add a doc comment to the public
method metadata describing what it does and its return value: explain that
forest::Car::metadata lazily initializes and returns an
Option<&FilecoinSnapshotMetadata>, that it attempts to read metadata from
header.roots when the snapshot has V2 root count
(super::V2_SNAPSHOT_ROOT_COUNT), calls get_cbor::<FilecoinSnapshotMetadata> on
the first root CID and returns Some(metadata) on success or None otherwise, and
note that the returned reference is cached for the lifetime of the CAR instance.
src/db/car/any.rs (1)

57-63: Add a doc comment for the public metadata API.

Line 57 changes a public method signature, but the method is still undocumented.

💡 Proposed doc comment
+    /// Returns snapshot metadata if present in the underlying CAR variant.
+    ///
+    /// For CAR files without v2 metadata, this returns `None`.
     pub fn metadata(&self) -> Option<&FilecoinSnapshotMetadata> {

As per coding guidelines: Document public functions and structs with doc comments.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/db/car/any.rs` around lines 57 - 63, Add a doc comment above the public
method AnyCar::metadata describing what it returns and when it can be None;
update the doc to mention the return type (Option<&FilecoinSnapshotMetadata>)
and that it delegates to the specific variants (Forest, Plain, Memory) via
forest.metadata(), plain.metadata(), mem.metadata(), so callers know the
semantic meaning and nullability of the metadata value.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/db/car/plain.rs`:
- Around line 176-189: Add a doc comment to the public method metadata() that
explains the two distinct reasons it can return None: (1) the CAR is not a v2
snapshot (check uses header_v1.roots.len() == super::V2_SNAPSHOT_ROOT_COUNT) and
(2) the metadata CID existed but loading/decoding via
get_cbor::<FilecoinSnapshotMetadata>(...) failed or returned None; reference
FilecoinSnapshotMetadata, header_v1.roots, V2_SNAPSHOT_ROOT_COUNT and get_cbor
in the comment so callers know how to interpret None.

In `@src/rpc/methods/chain.rs`:
- Around line 1067-1070: Add a doc comment above the public function
get_tipset_by_anchor explaining its fallback contract: when the anchor parameter
is None the function resolves to the finalized Tipset, when an explicit
TipsetAnchor is provided but represents a zero/empty anchor it falls back to the
heaviest Tipset, and otherwise it resolves according to the provided
TipsetAnchor; reference the TipsetAnchor and Tipset types in the comment so
callers understand the exact behavior.

In `@src/shim/actors/convert.rs`:
- Around line 93-96: Add a doc comment to the public function
from_opt_token_v4_to_v2 describing its behavior: explain that it converts a
TokenAmountV4 (by reference) to TokenAmountV2 and that when passed None it
returns TokenAmountV2::default(); include the rationale/intent and any
guarantees (e.g., cloning atto value via TokenAmountV2::from_atto) so callers
understand the fallback behavior and conversion semantics, following the crate's
doc-comment guideline for public APIs.

---

Nitpick comments:
In `@src/db/car/any.rs`:
- Around line 57-63: Add a doc comment above the public method AnyCar::metadata
describing what it returns and when it can be None; update the doc to mention
the return type (Option<&FilecoinSnapshotMetadata>) and that it delegates to the
specific variants (Forest, Plain, Memory) via forest.metadata(),
plain.metadata(), mem.metadata(), so callers know the semantic meaning and
nullability of the metadata value.

In `@src/db/car/forest.rs`:
- Around line 121-135: Add a doc comment to the public method metadata
describing what it does and its return value: explain that forest::Car::metadata
lazily initializes and returns an Option<&FilecoinSnapshotMetadata>, that it
attempts to read metadata from header.roots when the snapshot has V2 root count
(super::V2_SNAPSHOT_ROOT_COUNT), calls get_cbor::<FilecoinSnapshotMetadata> on
the first root CID and returns Some(metadata) on success or None otherwise, and
note that the returned reference is cached for the lifetime of the CAR instance.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: aa319cc0-3189-4ce9-8152-ed7d12027c17

📥 Commits

Reviewing files that changed from the base of the PR and between 30c9407 and a107265.

📒 Files selected for processing (20)
  • Cargo.toml
  • interop-tests/Cargo.toml
  • src/chain/tests.rs
  • src/cli/subcommands/mpool_cmd.rs
  • src/daemon/db_util.rs
  • src/db/car/any.rs
  • src/db/car/forest.rs
  • src/db/car/plain.rs
  • src/eth/eip_1559_transaction.rs
  • src/eth/eip_155_transaction.rs
  • src/eth/homestead_transaction.rs
  • src/eth/transaction.rs
  • src/ipld/tests/selector_explore.rs
  • src/rpc/methods/chain.rs
  • src/rpc/methods/eth.rs
  • src/rpc/methods/eth/filter/mod.rs
  • src/rpc/methods/eth/types.rs
  • src/rpc/types/tipset_selector.rs
  • src/shim/actors/convert.rs
  • src/utils/net/download_file.rs

@codecov
Copy link

codecov bot commented Mar 15, 2026

Codecov Report

❌ Patch coverage is 75.40984% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.45%. Comparing base (30c9407) to head (b2cc0a4).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/cli/subcommands/mpool_cmd.rs 76.92% 3 Missing ⚠️
src/db/car/plain.rs 83.33% 2 Missing ⚠️
src/shim/actors/convert.rs 0.00% 2 Missing ⚠️
src/daemon/db_util.rs 0.00% 0 Missing and 1 partial ⚠️
src/db/car/any.rs 0.00% 1 Missing ⚠️
src/eth/eip_1559_transaction.rs 50.00% 0 Missing and 1 partial ⚠️
src/eth/eip_155_transaction.rs 50.00% 0 Missing and 1 partial ⚠️
src/eth/homestead_transaction.rs 50.00% 0 Missing and 1 partial ⚠️
src/rpc/methods/chain.rs 50.00% 0 Missing and 1 partial ⚠️
src/rpc/methods/eth.rs 0.00% 0 Missing and 1 partial ⚠️
... and 1 more
Additional details and impacted files
Files with missing lines Coverage Δ
src/db/car/forest.rs 82.88% <100.00%> (+0.10%) ⬆️
src/eth/transaction.rs 86.82% <100.00%> (ø)
src/rpc/methods/eth/filter/mod.rs 88.04% <100.00%> (-0.10%) ⬇️
src/rpc/methods/eth/types.rs 76.04% <100.00%> (ø)
src/utils/net/download_file.rs 81.09% <100.00%> (ø)
src/daemon/db_util.rs 54.11% <0.00%> (ø)
src/db/car/any.rs 67.64% <0.00%> (ø)
src/eth/eip_1559_transaction.rs 89.79% <50.00%> (ø)
src/eth/eip_155_transaction.rs 84.27% <50.00%> (ø)
src/eth/homestead_transaction.rs 77.04% <50.00%> (ø)
... and 6 more

... and 8 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 30c9407...b2cc0a4. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@LesnyRumcajs LesnyRumcajs enabled auto-merge March 15, 2026 11:43
@LesnyRumcajs LesnyRumcajs added this pull request to the merge queue Mar 15, 2026
Merged via the queue into main with commit c7d9ba6 Mar 15, 2026
35 checks passed
@LesnyRumcajs LesnyRumcajs deleted the enable-ref-option-lints branch March 15, 2026 23:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants