Re: [PATCH] rust: devres: add 'static bound to Devres<T>

From: Gary Guo

Date: Wed May 27 2026 - 15:25:51 EST


On Wed May 27, 2026 at 7:13 PM BST, Danilo Krummrich wrote:
> On Wed May 27, 2026 at 8:07 PM CEST, Gary Guo wrote:
>> On Wed May 27, 2026 at 7:04 PM BST, Danilo Krummrich wrote:
>>> On Wed May 27, 2026 at 4:44 PM CEST, Gary Guo wrote:
>>>> On Tue May 26, 2026 at 1:04 AM BST, Danilo Krummrich wrote:
>>>>> Add a 'static bound to prevent storing types with borrowed data in
>>>>> Devres.
>>>>
>>>> The bound should be added on `Devres::new` instead.
>>>
>>> I did consider this as it is generally recommended to minimize bounds on
>>> structs.
>>>
>>> However, a Devres<T> with non-'static T is semantically nonsensical, not just
>>> unconstructible, and I think type level bound represents that better.
>>
>> Technically `Devres` can contain references to the registration, which is known
>> to outlive the bound device.
>
> That's technically true, but how would you express "outlives the device" as a
> lifetime bound on Devres?

Just having the lifetime would mean it outlives the device (lifetimes that
cannot be guaranteed to outlive the device cannot be used in devres).

In a world with registration data, I would imagine all lifetime parameters on
registration data are also valid for `Devres`.

>
> Additionally, if the borrowed data outlives the device bound, you don't need
> device-managed revocation for it in the first place.

Resources that depend on both registration data and device resource perhaps?

Best,
Gary