* build warning in libgpiod rust bindings with rust 1.83
@ 2024-12-20 16:25 Bartosz Golaszewski
2024-12-21 2:01 ` Kent Gibson
0 siblings, 1 reply; 3+ messages in thread
From: Bartosz Golaszewski @ 2024-12-20 16:25 UTC (permalink / raw)
To: Viresh Kumar; +Cc: open list:GPIO SUBSYSTEM, Erik Schilling, Kent Gibson
Hi Viresh et al,
I noticed the following warning when building libgpiod rust bindings
with rust 1.83:
warning: elided lifetime has a name
--> libgpiod/src/line_request.rs:234:26
|
231 | pub fn read_edge_events<'a>(
| -- lifetime `'a` declared here
...
234 | ) -> Result<request::Events> {
| ^^^^^^ this elided lifetime gets resolved as `'a`
|
= note: `#[warn(elided_named_lifetimes)]` on by default
Could you please take a look as I have no idea what that means?
Best regards
Bartosz
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: build warning in libgpiod rust bindings with rust 1.83
2024-12-20 16:25 build warning in libgpiod rust bindings with rust 1.83 Bartosz Golaszewski
@ 2024-12-21 2:01 ` Kent Gibson
2025-01-02 7:42 ` Erik Schilling
0 siblings, 1 reply; 3+ messages in thread
From: Kent Gibson @ 2024-12-21 2:01 UTC (permalink / raw)
To: Bartosz Golaszewski
Cc: Viresh Kumar, open list:GPIO SUBSYSTEM, Erik Schilling
On Fri, Dec 20, 2024 at 05:25:16PM +0100, Bartosz Golaszewski wrote:
> Hi Viresh et al,
>
> I noticed the following warning when building libgpiod rust bindings
> with rust 1.83:
>
> warning: elided lifetime has a name
> --> libgpiod/src/line_request.rs:234:26
> |
> 231 | pub fn read_edge_events<'a>(
> | -- lifetime `'a` declared here
> ...
> 234 | ) -> Result<request::Events> {
> | ^^^^^^ this elided lifetime gets resolved as `'a`
> |
> = note: `#[warn(elided_named_lifetimes)]` on by default
>
> Could you please take a look as I have no idea what that means?
>
clippy is complaining that the lifetime of the returned object is implicit.
Try:
--- a/bindings/rust/libgpiod/src/line_request.rs
+++ b/bindings/rust/libgpiod/src/line_request.rs
@@ -231,7 +231,7 @@ impl Request {
pub fn read_edge_events<'a>(
&'a self,
buffer: &'a mut request::Buffer,
- ) -> Result<request::Events> {
+ ) -> Result<request::Events<'a>> {
buffer.read_edge_events(self)
}
}
to make it explicit.
Cheers,
Kent.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: build warning in libgpiod rust bindings with rust 1.83
2024-12-21 2:01 ` Kent Gibson
@ 2025-01-02 7:42 ` Erik Schilling
0 siblings, 0 replies; 3+ messages in thread
From: Erik Schilling @ 2025-01-02 7:42 UTC (permalink / raw)
To: Kent Gibson, Bartosz Golaszewski; +Cc: Viresh Kumar, open list:GPIO SUBSYSTEM
Sorry! I was mostly offline over the holidays.
On Sat Dec 21, 2024 at 3:01 AM CET, Kent Gibson wrote:
> On Fri, Dec 20, 2024 at 05:25:16PM +0100, Bartosz Golaszewski wrote:
> > Hi Viresh et al,
> >
> > I noticed the following warning when building libgpiod rust bindings
> > with rust 1.83:
> >
> > warning: elided lifetime has a name
> > --> libgpiod/src/line_request.rs:234:26
> > |
> > 231 | pub fn read_edge_events<'a>(
> > | -- lifetime `'a` declared here
> > ...
> > 234 | ) -> Result<request::Events> {
> > | ^^^^^^ this elided lifetime gets resolved as `'a`
> > |
> > = note: `#[warn(elided_named_lifetimes)]` on by default
> >
> > Could you please take a look as I have no idea what that means?
> >
>
> clippy is complaining that the lifetime of the returned object is implicit.
>
> Try:
>
> --- a/bindings/rust/libgpiod/src/line_request.rs
> +++ b/bindings/rust/libgpiod/src/line_request.rs
> @@ -231,7 +231,7 @@ impl Request {
> pub fn read_edge_events<'a>(
> &'a self,
> buffer: &'a mut request::Buffer,
> - ) -> Result<request::Events> {
> + ) -> Result<request::Events<'a>> {
> buffer.read_edge_events(self)
> }
> }
>
> to make it explicit.
Thats overall correct. Though this is an actual compiler warning and not
coming from clippy.
But looking in a bit more detail I think the 'a on &self is wrong:
--- a/bindings/rust/libgpiod/src/line_request.rs
+++ b/bindings/rust/libgpiod/src/line_request.rs
@@ -230,7 +230,7 @@ impl Request {
/// This function will block if no event was queued for the line.
pub fn read_edge_events<'a>(
- &'a self,
+ &self,
buffer: &'a mut request::Buffer,
- ) -> Result<request::Events> {
+ ) -> Result<request::Events<'a>> {
buffer.read_edge_events(self)
}
The lifetime is needed because the returned event reference is linked
to the lifetime of the buffer. With the &'a self the compiler will add a
<'a> to the return value.
But there is no dependency on the Request reference that extends longer
than this function call. Instead we want to explicitly break up the tie
to the &self and tie it to the buffer instead!
Sent a patch: https://lore.kernel.org/r/20250102-lifetime-fix-v1-1-313a6bc806c4@linaro.org/
- Erik
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-01-02 7:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-20 16:25 build warning in libgpiod rust bindings with rust 1.83 Bartosz Golaszewski
2024-12-21 2:01 ` Kent Gibson
2025-01-02 7:42 ` Erik Schilling
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox