ForLt/CovariantForLt split, auxiliary closure API and DevresLt

The ForLt trait currently guarantees covariance, which allows safe
 lifetime shortening via cast_ref(). However, some types (e.g. those
 containing Mutex<&'bound T>) are invariant over their lifetime parameter
 and cannot safely use cast_ref().
 
 This series splits ForLt into two traits:
 
   - ForLt: base trait for all lifetime-parameterized types, providing
     only the Of<'a> GAT.
 
   - CovariantForLt: unsafe subtrait that guarantees covariance,
     providing a safe cast_ref() method.
 
 For invariant types, a closure-based API (registration_data_with()) is
 added to the auxiliary subsystem. The closure's HRTB prevents the caller
 from choosing a concrete lifetime, which would be unsound for invariant
 types.
 
 On top of that, this series adds DevresLt<F: ForLt>, a thin wrapper
 around Devres<F::Of<'static>> that shortens the stored 'static lifetime
 back to the caller's borrow scope. DevresLt provides both closure-based
 access (access_with/try_access_with for ForLt types) and direct
 reference access (access/try_access for CovariantForLt types).
 
 Also implement ForLt and CovariantForLt for Bar, IoMem and
 ExclusiveIoMem, and update their into_devres() methods to return
 DevresLt. Provide convenience type aliases DevresBar, DevresIoMem and
 DevresExclusiveIoMem.
 
 This is a stable tag for other trees to merge.
 -----BEGIN PGP SIGNATURE-----
 
 iHUEABYKAB0WIQS2q/xV6QjXAdC7k+1FlHeO1qrKLgUCalVYCAAKCRBFlHeO1qrK
 Lv66AQCcu91WcBr1jpsMOptgN6rfg9WRqzn4Z69X2dKRz4XZKwD/Z3ihPBAuoDr8
 eqKjYG6cCV/qhEVgr0SctOO2xHVTVAE=
 =iqDJ
 -----END PGP SIGNATURE-----

Merge patch series "ForLt/CovariantForLt split, auxiliary closure API and DevresLt"

Danilo Krummrich <dakr@kernel.org> says:

The ForLt trait currently guarantees covariance, which allows safe
lifetime shortening via cast_ref(). However, some types (e.g. those
containing Mutex<&'bound T>) are invariant over their lifetime parameter
and cannot safely use cast_ref().

This series splits ForLt into two traits:

  - ForLt: base trait for all lifetime-parameterized types, providing
    only the Of<'a> GAT.

  - CovariantForLt: unsafe subtrait that guarantees covariance,
    providing a safe cast_ref() method.

For invariant types, a closure-based API (registration_data_with()) is
added to the auxiliary subsystem. The closure's HRTB prevents the caller
from choosing a concrete lifetime, which would be unsound for invariant
types.

On top of that, this series adds DevresLt<F: ForLt>, a thin wrapper
around Devres<F::Of<'static>> that shortens the stored 'static lifetime
back to the caller's borrow scope. DevresLt provides both closure-based
access (access_with/try_access_with for ForLt types) and direct
reference access (access/try_access for CovariantForLt types).

Also implement ForLt and CovariantForLt for Bar, IoMem and
ExclusiveIoMem, and update their into_devres() methods to return
DevresLt. Provide convenience type aliases DevresBar, DevresIoMem and
DevresExclusiveIoMem.

Link: https://patch.msgid.link/20260626183630.2585057-1-dakr@kernel.org
Signed-off-by: Danilo Krummrich <dakr@kernel.org>
This commit is contained in:
Danilo Krummrich 2026-07-13 23:34:30 +02:00
commit a56a92be1f
12 changed files with 436 additions and 123 deletions