public inbox for drm-ai-reviews@public-inbox.freedesktop.org
 help / color / mirror / Atom feed
From: Claude Code Review Bot <claude-review@example.com>
To: dri-devel-reviews@example.com
Subject: Claude review: rust: sync: lock: Add Lock::get_mut_pinned()
Date: Wed, 27 May 2026 14:07:41 +1000	[thread overview]
Message-ID: <review-patch1-20260526205419.1055109-2-lyude@redhat.com> (raw)
In-Reply-To: <20260526205419.1055109-2-lyude@redhat.com>

Patch Review

This patch adds a method to `Lock` that provides `Pin<&mut T>` access when you hold a `Pin<&mut Lock<...>>`, bypassing the actual locking since `&mut` guarantees exclusivity at compile time. This mirrors `std::sync::Mutex::get_mut()`.

**Correctness**: The implementation is sound. `Lock::data` is declared as `#[pin] pub(crate) data: UnsafeCell<T>` (lock.rs:118-119), so `T` is structurally pinned within the `Lock`. Having `Pin<&mut Self>` guarantees exclusive access, and returning `Pin<&mut T>` preserves the pin projection correctly. The `map_unchecked_mut` + `UnsafeCell::get_mut` path is the standard pattern.

**Minor items**:

1. The SAFETY comment is slightly sparse:
```rust
// SAFETY: We return a pinned T, ensuring we don't move T.
unsafe { self.map_unchecked_mut(|data| data.data.get_mut()) }
```
It would be more precise to note *why* this is a valid pin projection — i.e., that `data` is structurally pinned within `Lock` (via `#[pin]` on the field). The current comment explains the output constraint (we don't move T) but not the input justification (the field is structurally pinned). This is minor since the `#[pin]` attribute is visible on the struct definition.

2. The `#[inline(always)]` is arguably aggressive for a method that will likely only be called in `Drop` paths and similar low-frequency situations. `#[inline]` would be sufficient, consistent with the existing `lock()` and `try_lock()` methods in the same `impl` block.

3. The commit message references "These two functions" (plural), but only one function is added. Looks like the commit message may have been written when a non-pinned `get_mut()` was also planned.

**Verdict**: Good. The approach is correct and matches standard Rust practice.

---

---
Generated by Claude Code Patch Reviewer

  reply	other threads:[~2026-05-27  4:07 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-26 20:41 [PATCH 0/2] rust: sync: Introduce LazyInit Lyude Paul
2026-05-26 20:41 ` [PATCH 1/2] rust: sync: lock: Add Lock::get_mut_pinned() Lyude Paul
2026-05-27  4:07   ` Claude Code Review Bot [this message]
2026-05-26 20:41 ` [PATCH 2/2] rust: sync: Introduce LazyInit Lyude Paul
2026-05-27  4:07   ` Claude review: " Claude Code Review Bot
2026-05-27  4:07 ` Claude Code Review Bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=review-patch1-20260526205419.1055109-2-lyude@redhat.com \
    --to=claude-review@example.com \
    --cc=dri-devel-reviews@example.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox