From mboxrd@z Thu Jan 1 00:00:00 1970 From: Claude Code Review Bot To: dri-devel-reviews@example.com Subject: Claude review: rust: auxiliary: generalize Registration over ForLt Date: Mon, 25 May 2026 19:29:15 +1000 Message-ID: In-Reply-To: <20260521233501.1191842-23-dakr@kernel.org> References: <20260521233501.1191842-1-dakr@kernel.org> <20260521233501.1191842-23-dakr@kernel.org> X-Mailer: Claude Code Patch Reviewer Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Patch Review Converts `Registration` to `Registration<'a, F: ForLt + 'static= >`. Two constructors: 1. `unsafe fn new_with_lt()` =E2=80=94 for borrowed data, caller must not `= mem::forget()` the Registration 2. `fn new()` =E2=80=94 safe, requires `F::Of<'a>: 'static` The `PhantomData<(fn(&'a ()) -> &'a (), F)>` uses the `fn(&'a ()) -> &'a ()= ` trick to make `'a` invariant (not covariant or contravariant), which is c= orrect for a type that holds data borrowed for `'a`. The `registration_data()` method now uses `TypeId::of::()` (the ForLt ty= pe itself, not `F::Of<'static>`) for the type check. This is correct becaus= e `F` is `'static` (trait bound) and uniquely identifies the type family. The transmute in `new_with_lt`: ```rust let data: Pin>>> =3D unsafe { core::mem::transmute(data) }; ``` This widens `F::Of<'a>` to `F::Of<'static>` for storage. The safety argumen= t is that `Registration`'s Drop will release this data before `'a` ends (en= forced by the unsafe contract on `new_with_lt`). Combined with ForLt's cova= riance, the `cast_ref` in `registration_data()` can safely shorten back fro= m `'static` to the borrow scope. **The `mem::forget` soundness hole is well-addressed** by splitting into sa= fe/unsafe constructors. The safe `new()` has `F::Of<'a>: 'static`, meaning = forgetting is harmless. The unsafe `new_with_lt()` documents the requiremen= t. The `Send`/`Sync` bounds use `for<'a> F::Of<'a>: Send` which is correct =E2= =80=94 the data must be Send for all possible lifetimes since the actual st= ored lifetime is erased to `'static`. --- --- Generated by Claude Code Patch Reviewer