From: "Erik Schilling" <erik.schilling@linaro.org>
To: "Kent Gibson" <warthog618@gmail.com>,
"Bartosz Golaszewski" <brgl@bgdev.pl>
Cc: "Viresh Kumar" <viresh.kumar@linaro.org>,
"open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>
Subject: Re: build warning in libgpiod rust bindings with rust 1.83
Date: Thu, 02 Jan 2025 08:42:45 +0100 [thread overview]
Message-ID: <D6RF2X71A2QX.3D8K6N3TPKFPU@linaro.org> (raw)
In-Reply-To: <20241221020102.GA45199@rigel>
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
prev parent reply other threads:[~2025-01-02 7:42 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=D6RF2X71A2QX.3D8K6N3TPKFPU@linaro.org \
--to=erik.schilling@linaro.org \
--cc=brgl@bgdev.pl \
--cc=linux-gpio@vger.kernel.org \
--cc=viresh.kumar@linaro.org \
--cc=warthog618@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox