Skip to content

Add struct destructuring to catch missing fields at compile time - #8497

Merged
agourlay merged 1 commit into
devfrom
add-struct-destructuring
Mar 24, 2026
Merged

agourlay merged 1 commit into
devfrom
add-struct-destructuring

Conversation

@qdrant-cloud-bot

Copy link
Copy Markdown
Contributor

Summary

  • Adds struct destructuring (pattern matching) in 12 locations across the codebase where struct fields were previously accessed individually via dot notation (value.field). This ensures the compiler will produce an error when a new field is added to a struct but not handled in these conversion/construction sites.
  • Prevents a common class of bugs where a newly added struct field is silently ignored in From/TryFrom impls, key extraction methods, and config builders.

Covered spots

# Location Conversion Fields
1 operations/conversions.rs RecommendPointGroups → RecommendGroupsRequestInternal 15
2 telemetry.rs grpc::ShardTransferTelemetry → ShardTransferInfo 7
3 telemetry.rs ShardTransferInfo → grpc::ShardTransferTelemetry 7
4 telemetry.rs grpc::ReshardingTelemetry → ReshardingInfo 6
5 telemetry.rs ReshardingInfo → grpc::ReshardingTelemetry 6
6 grpc/conversions.rs HwMeasurementAcc → HardwareUsage (via HardwareData destructuring) 7
7 request_hw_counter.rs to_rest_api and to_grpc_api (via HardwareData destructuring) 7 x2
8 optimizers_builder.rs VectorParams + SparseVectorParams in build_segment_optimizer_config 7+2
9 config.rs VectorParams in to_base_vector_data 7
10 transfer/mod.rs ShardTransfer::key, ShardTransferRestart::key, from_transfer 4-5 each
11 resharding.rs ReshardState::matches and ReshardState::key 5 each
12 snapshot_ops.rs, lookup/types.rs, compat.rs SnapshotDescription, WithLookup, SegmentConfigV5 conversions 3-5 each

Test plan

  • cargo check passes
  • cargo +nightly fmt --all -- --check passes
  • CI tests pass (pure refactor, no behavioral changes)

Made with Cursor

Destructure structs in conversions, key/match functions, and config
builders so the compiler will error when new fields are added but not
handled. This prevents a common class of bugs where a newly added
struct field is silently ignored.

Covered spots:
- RecommendPointGroups → RecommendGroupsRequestInternal (15 fields)
- ShardTransferTelemetry ↔ ShardTransferInfo (7 fields, both directions)
- ReshardingTelemetry ↔ ReshardingInfo (6 fields, both directions)
- HwMeasurementAcc → HardwareUsage (7 fields, 3 call sites)
- VectorParams destructuring in optimizers_builder and config (7 fields)
- SparseVectorParams destructuring in optimizers_builder (2 fields)
- ShardTransfer → ShardTransferRestart (5 fields)
- ReshardState::matches and ReshardState::key (5 fields each)
- ShardTransfer::key and ShardTransferRestart::key (4 fields each)
- SnapshotDescription → grpc (4 fields)
- WithLookup REST → internal (3 fields)
- SegmentConfigV5 → SegmentConfig (5 fields)

Made-with: Cursor
@coderabbitai

coderabbitai Bot commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b8abe235-99c2-4683-8f13-770f29e8837a

📥 Commits

Reviewing files that changed from the base of the PR and between 1a2406d and df83d1b.

📒 Files selected for processing (11)
  • lib/api/src/grpc/conversions.rs
  • lib/collection/src/config.rs
  • lib/collection/src/lookup/types.rs
  • lib/collection/src/operations/conversions.rs
  • lib/collection/src/operations/snapshot_ops.rs
  • lib/collection/src/optimizers_builder.rs
  • lib/collection/src/shards/resharding.rs
  • lib/collection/src/shards/transfer/mod.rs
  • lib/collection/src/telemetry.rs
  • lib/segment/src/compat.rs
  • lib/storage/src/content_manager/toc/request_hw_counter.rs

📝 Walkthrough

Walkthrough

This PR refactors field access patterns across 11 files by systematically replacing direct field access (e.g., value.field, params.field) with destructuring assignments. Affected conversions span gRPC/REST API type mappings, internal struct conversions, and utility methods in the collection, segment, and storage layers. The destructured fields are then used to construct result types or perform operations. All changes maintain semantic equivalence and do not alter method signatures or public API declarations.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Clippy 1.87 autofix #6516: Both PRs modify the same conversion implementation (From<SegmentConfigV5> for SegmentConfig) in lib/segment/src/compat.rs.

Suggested reviewers

  • timvisee
  • generall
  • agourlay
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 21.05% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add struct destructuring to catch missing fields at compile time' clearly and accurately summarizes the main change—introducing struct destructuring patterns across the codebase to force compiler errors when new fields are added.
Description check ✅ Passed The description comprehensively explains the purpose (preventing silent field omission in conversions), lists 12 affected locations with clear categorization, and provides test plan evidence (cargo check and formatting checks passed).

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch add-struct-destructuring

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 and usage tips.

@agourlay
agourlay requested a review from JojiiOfficial March 24, 2026 14:13
@agourlay
agourlay merged commit dcd5f7a into dev Mar 24, 2026
15 checks passed
@agourlay
agourlay deleted the add-struct-destructuring branch March 24, 2026 14:53
generall pushed a commit that referenced this pull request Mar 26, 2026
Destructure structs in conversions, key/match functions, and config
builders so the compiler will error when new fields are added but not
handled. This prevents a common class of bugs where a newly added
struct field is silently ignored.

Covered spots:
- RecommendPointGroups → RecommendGroupsRequestInternal (15 fields)
- ShardTransferTelemetry ↔ ShardTransferInfo (7 fields, both directions)
- ReshardingTelemetry ↔ ReshardingInfo (6 fields, both directions)
- HwMeasurementAcc → HardwareUsage (7 fields, 3 call sites)
- VectorParams destructuring in optimizers_builder and config (7 fields)
- SparseVectorParams destructuring in optimizers_builder (2 fields)
- ShardTransfer → ShardTransferRestart (5 fields)
- ReshardState::matches and ReshardState::key (5 fields each)
- ShardTransfer::key and ShardTransferRestart::key (4 fields each)
- SnapshotDescription → grpc (4 fields)
- WithLookup REST → internal (3 fields)
- SegmentConfigV5 → SegmentConfig (5 fields)

Made-with: Cursor

Co-authored-by: Cursor Agent <[email protected]>
KShivendu pushed a commit that referenced this pull request Mar 30, 2026
Destructure structs in conversions, key/match functions, and config
builders so the compiler will error when new fields are added but not
handled. This prevents a common class of bugs where a newly added
struct field is silently ignored.

Covered spots:
- RecommendPointGroups → RecommendGroupsRequestInternal (15 fields)
- ShardTransferTelemetry ↔ ShardTransferInfo (7 fields, both directions)
- ReshardingTelemetry ↔ ReshardingInfo (6 fields, both directions)
- HwMeasurementAcc → HardwareUsage (7 fields, 3 call sites)
- VectorParams destructuring in optimizers_builder and config (7 fields)
- SparseVectorParams destructuring in optimizers_builder (2 fields)
- ShardTransfer → ShardTransferRestart (5 fields)
- ReshardState::matches and ReshardState::key (5 fields each)
- ShardTransfer::key and ShardTransferRestart::key (4 fields each)
- SnapshotDescription → grpc (4 fields)
- WithLookup REST → internal (3 fields)
- SegmentConfigV5 → SegmentConfig (5 fields)

Made-with: Cursor

Co-authored-by: Cursor Agent <[email protected]>
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.

4 participants