Re: [PATCH] rust: devres: add 'static bound to Devres<T>
From: Danilo Krummrich
Date: Wed May 27 2026 - 15:51:15 EST
On Wed May 27, 2026 at 9:25 PM CEST, Gary Guo wrote:
> 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`.
[...]
> Resources that depend on both registration data and device resource perhaps?
You'd still need a separate constructor for this, and I'm still not convinced
that this makes a lot of sense.
That said if you feel strongly about it, I don't mind moving the 'static bound
to new() too much.