[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <D9HAC6KW2GTG.ICOFCQX4A2U3@proton.me>
Date: Sun, 27 Apr 2025 08:41:02 +0000
From: Benno Lossin <benno.lossin@...ton.me>
To: Danilo Krummrich <dakr@...nel.org>
Cc: gregkh@...uxfoundation.org, rafael@...nel.org, bhelgaas@...gle.com, kwilczynski@...nel.org, zhiw@...dia.com, cjia@...dia.com, jhubbard@...dia.com, bskeggs@...dia.com, acurrid@...dia.com, joelagnelf@...dia.com, ttabi@...dia.com, acourbot@...dia.com, ojeda@...nel.org, alex.gaynor@...il.com, boqun.feng@...il.com, gary@...yguo.net, bjorn3_gh@...tonmail.com, a.hindborg@...nel.org, aliceryhl@...gle.com, tmgross@...ch.edu, linux-pci@...r.kernel.org, rust-for-linux@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 2/3] rust: devres: implement Devres::access_with()
On Sat Apr 26, 2025 at 11:24 PM CEST, Danilo Krummrich wrote:
> On Sat, Apr 26, 2025 at 08:28:30PM +0000, Benno Lossin wrote:
>> On Sat Apr 26, 2025 at 3:30 PM CEST, Danilo Krummrich wrote:
>> > + pub fn access_with<'s, 'd: 's>(&'s self, dev: &'d Device<Bound>) -> Result<&'s T> {
>>
>> I don't think that we need the `'d` lifetime here (if not, we should
>> remove it).
>
> If the returned reference out-lives dev it can become invalid, since it means
> that the device could subsequently be unbound. Hence, I think we indeed need to
> require that the returned reference cannot out-live dev.
I meant the following signature:
pub fn access_with<'a>(&'a self, dev: &'a Device<Bound>) -> Result<&'a T>
You don't need to specify the additional `'d` one, since lifetimes allow
subtyping [1]. So if I have a `&'s self` and a `&'d Device<Bound>` and
`'d: 's`, then I can supply those arguments to my suggested function and
the compiler will shorten `'d` to be `'s` or whatever is correct in the
context.
[1]: https://doc.rust-lang.org/nomicon/subtyping.html#subtyping
---
Cheers,
Benno
Powered by blists - more mailing lists