Skip to content

Add #[must_use] to RAII guard and task handle types - #8499

Merged
generall merged 2 commits into
devfrom
add-must-use-guards
Mar 25, 2026
Merged

generall merged 2 commits into
devfrom
add-must-use-guards

Conversation

@qdrant-cloud-bot

Copy link
Copy Markdown
Contributor

Summary

  • Adds #[must_use] with descriptive messages to 8 RAII guard and task handle types whose correctness depends on being held for a scope
  • Guards: StoppingGuard, UpdateGuard, UpdatesGuard, ClockGuard, IsAliveGuard, ScopeTrackerGuard
  • Task handles: CancellableAsyncTaskHandle, StoppableTaskHandle
  • All of these have Drop implementations (or wrap types that do) where dropping immediately is a silent correctness bug — the compiler will now warn if a value of these types is unused

The codebase already follows this pattern in a few places (e.g. CountedProcessHandle has #[must_use = "Dropping this handle will immediately decrease the process count"]), this PR extends it consistently to other types that fit the same criteria.

Test plan

  • cargo check passes cleanly on common, collection, and shard crates with no new warnings
  • No behavioral changes — #[must_use] is a lint-only annotation

Made with Cursor

These types rely on being held for a scope — dropping them immediately is
almost always a bug:

- `StoppingGuard`: sets `is_stopped` flag on drop
- `UpdateGuard`: decrements update counter on drop
- `UpdatesGuard`: releases mutex preventing concurrent updates on drop
- `ClockGuard`: marks clock as inactive on drop
- `IsAliveGuard`: releases liveness lock on drop
- `ScopeTrackerGuard`: decrements scope counter on drop
- `CancellableAsyncTaskHandle`: detaches task on drop
- `StoppableTaskHandle`: may abort task on drop (AbortOnDropHandle)

Made-with: Cursor
With ScopeTrackerGuard marked #[must_use] at the type level, the
function-level attributes on measure_scope(), measure(),
track_create_snapshot_request(), and count_snapshot_creation() are
redundant and trigger clippy::double_must_use.

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: 984f75de-8a17-4d2a-a607-e21fef629222

📥 Commits

Reviewing files that changed from the base of the PR and between dcd5f7a and 6b76822.

📒 Files selected for processing (10)
  • lib/collection/src/common/stoppable_task.rs
  • lib/collection/src/common/stoppable_task_async.rs
  • lib/collection/src/shards/replica_set/clock_set.rs
  • lib/collection/src/shards/replica_set/partial_snapshot_meta.rs
  • lib/collection/src/shards/update_tracker.rs
  • lib/common/common/src/is_alive_lock.rs
  • lib/common/common/src/scope_tracker.rs
  • lib/shard/src/common/stopping_guard.rs
  • lib/shard/src/segment_holder/locked.rs
  • lib/storage/src/content_manager/toc/telemetry.rs
💤 Files with no reviewable changes (2)
  • lib/collection/src/shards/replica_set/partial_snapshot_meta.rs
  • lib/storage/src/content_manager/toc/telemetry.rs

📝 Walkthrough

Walkthrough

This pull request systematically adds #[must_use] attributes with specific compiler warning messages to multiple guard and handle types across the codebase (stoppable task handles, clock guards, update guards, scope tracker guards, and others). Additionally, #[must_use] attributes are removed from two methods to consolidate the requirement at the guard type level rather than the method level. No logic, control flow, or runtime behavior is altered.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested reviewers

  • coszio
  • timvisee
  • IvanPleshkov
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding #[must_use] attributes to RAII guard and task handle types across the codebase.
Description check ✅ Passed The description clearly explains the purpose of the changes, lists the affected types, provides context about the pattern being followed, and documents the test plan.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% 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
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch add-must-use-guards

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 timvisee March 24, 2026 16:25
@generall
generall merged commit 401cb7f into dev Mar 25, 2026
15 checks passed
@generall
generall deleted the add-must-use-guards branch March 25, 2026 13:51
generall pushed a commit that referenced this pull request Mar 26, 2026
* Add `#[must_use]` to RAII guard and task handle types

These types rely on being held for a scope — dropping them immediately is
almost always a bug:

- `StoppingGuard`: sets `is_stopped` flag on drop
- `UpdateGuard`: decrements update counter on drop
- `UpdatesGuard`: releases mutex preventing concurrent updates on drop
- `ClockGuard`: marks clock as inactive on drop
- `IsAliveGuard`: releases liveness lock on drop
- `ScopeTrackerGuard`: decrements scope counter on drop
- `CancellableAsyncTaskHandle`: detaches task on drop
- `StoppableTaskHandle`: may abort task on drop (AbortOnDropHandle)

Made-with: Cursor

* Remove redundant function-level #[must_use] now covered by type

With ScopeTrackerGuard marked #[must_use] at the type level, the
function-level attributes on measure_scope(), measure(),
track_create_snapshot_request(), and count_snapshot_creation() are
redundant and trigger clippy::double_must_use.

Made-with: Cursor

---------

Co-authored-by: Cursor Agent <[email protected]>
KShivendu pushed a commit that referenced this pull request Mar 30, 2026
* Add `#[must_use]` to RAII guard and task handle types

These types rely on being held for a scope — dropping them immediately is
almost always a bug:

- `StoppingGuard`: sets `is_stopped` flag on drop
- `UpdateGuard`: decrements update counter on drop
- `UpdatesGuard`: releases mutex preventing concurrent updates on drop
- `ClockGuard`: marks clock as inactive on drop
- `IsAliveGuard`: releases liveness lock on drop
- `ScopeTrackerGuard`: decrements scope counter on drop
- `CancellableAsyncTaskHandle`: detaches task on drop
- `StoppableTaskHandle`: may abort task on drop (AbortOnDropHandle)

Made-with: Cursor

* Remove redundant function-level #[must_use] now covered by type

With ScopeTrackerGuard marked #[must_use] at the type level, the
function-level attributes on measure_scope(), measure(),
track_create_snapshot_request(), and count_snapshot_creation() are
redundant and trigger clippy::double_must_use.

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