linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH libgpiod 0/3] bindings: rust: fix some compiler + clippy warnings
@ 2025-01-02  7:40 Erik Schilling
  2025-01-02  7:40 ` [PATCH libgpiod 1/3] bindings: rust: libgpiod: make read_edge_events lifetimes more explicit Erik Schilling
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Erik Schilling @ 2025-01-02  7:40 UTC (permalink / raw)
  To: Linux-GPIO, Bartosz Golaszewski
  Cc: Erik Schilling, Viresh Kumar, Kent Gibson, Bartosz Golaszewski

Triggered by the discussion at:
https://lore.kernel.org/r/CAMRc=Me-QNmJ2L1K-gGzFtVZacsDiLsNUfh3QaWPdbVzyxUduA@mail.gmail.com/

I also found some clippy warnings that I fixed while having the editor
open.

Signed-off-by: Erik Schilling <erik.schilling@linaro.org>
---
Erik Schilling (3):
      bindings: rust: libgpiod: make read_edge_events lifetimes more explicit
      bindings: rust: libgpiod: turn standalone doc comment into normal comment
      bindings: rust: libpgiod: fix clippy::empty_line_after_doc_comments lint

 bindings/rust/libgpiod/src/event_buffer.rs | 1 -
 bindings/rust/libgpiod/src/lib.rs          | 2 +-
 bindings/rust/libgpiod/src/line_request.rs | 4 ++--
 3 files changed, 3 insertions(+), 4 deletions(-)
---
base-commit: 38adbae195555fae2b9d9e2a37c9507af1114757
change-id: 20250102-lifetime-fix-ccdb8562a2de

Best regards,
-- 
Erik Schilling <erik.schilling@linaro.org>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH libgpiod 1/3] bindings: rust: libgpiod: make read_edge_events lifetimes more explicit
  2025-01-02  7:40 [PATCH libgpiod 0/3] bindings: rust: fix some compiler + clippy warnings Erik Schilling
@ 2025-01-02  7:40 ` Erik Schilling
  2025-01-02  7:40 ` [PATCH libgpiod 2/3] bindings: rust: libgpiod: turn standalone doc comment into normal comment Erik Schilling
  2025-01-02  7:40 ` [PATCH libgpiod 3/3] bindings: rust: libpgiod: fix clippy::empty_line_after_doc_comments lint Erik Schilling
  2 siblings, 0 replies; 6+ messages in thread
From: Erik Schilling @ 2025-01-02  7:40 UTC (permalink / raw)
  To: Linux-GPIO, Bartosz Golaszewski
  Cc: Erik Schilling, Viresh Kumar, Kent Gibson, Bartosz Golaszewski

Newer rustc versions warn on elided named lifetimes. In thise case, it
actually revealed a misleading function signature.

The function defined &self with 'a. But there is no dependency on the
Request reference that extends longer than this function call. Yet,
the code expresses such a dependency and abuses it to force the buffer
argument to match &self lifetime (and thus the return lifetime too!).

Instead we want to explicitly break up the tie to the &self and tie it
to the buffer instead.

The 'a on &self caused a 'a on the return. With that being removed we
would get an automatic '0. So we are now forced to add the 'a on the
return that also fixes the compiler warning.

Reported-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Co-authored-by: Kent Gibson <warthog618@gmail.com>
Link: https://lore.kernel.org/r/CAMRc=Me-QNmJ2L1K-gGzFtVZacsDiLsNUfh3QaWPdbVzyxUduA@mail.gmail.com/
---
 bindings/rust/libgpiod/src/line_request.rs | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/bindings/rust/libgpiod/src/line_request.rs b/bindings/rust/libgpiod/src/line_request.rs
index 7ec65085780e19499e08817e562ff0f9c004a6ee..d7b62a1a083ff589aaa4fa3edb1b1269e7aafaf5 100644
--- a/bindings/rust/libgpiod/src/line_request.rs
+++ b/bindings/rust/libgpiod/src/line_request.rs
@@ -225,17 +225,17 @@ impl Request {
         }
     }
 
     /// Get a number of edge events from a line 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)
     }
 }
 
 impl AsRawFd for Request {
     /// Get the file descriptor associated with the line request.
     fn as_raw_fd(&self) -> i32 {

-- 
2.47.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH libgpiod 2/3] bindings: rust: libgpiod: turn standalone doc comment into normal comment
  2025-01-02  7:40 [PATCH libgpiod 0/3] bindings: rust: fix some compiler + clippy warnings Erik Schilling
  2025-01-02  7:40 ` [PATCH libgpiod 1/3] bindings: rust: libgpiod: make read_edge_events lifetimes more explicit Erik Schilling
@ 2025-01-02  7:40 ` Erik Schilling
  2025-01-03 14:32   ` Bartosz Golaszewski
  2025-01-02  7:40 ` [PATCH libgpiod 3/3] bindings: rust: libpgiod: fix clippy::empty_line_after_doc_comments lint Erik Schilling
  2 siblings, 1 reply; 6+ messages in thread
From: Erik Schilling @ 2025-01-02  7:40 UTC (permalink / raw)
  To: Linux-GPIO, Bartosz Golaszewski; +Cc: Erik Schilling, Viresh Kumar, Kent Gibson

This was complained about by clippy:

    warning: empty line after doc comment
       --> libgpiod/src/lib.rs:461:1
        |
    461 | / /// Various libgpiod-related functions.
    462 | |
        | |_
    ...
    467 |   pub fn is_gpiochip_device<P: AsRef<Path>>(path: &P) -> bool {
        |   ----------------------------------------------------------- the comment documents this function
        |
        = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments
        = help: if the empty line is unintentional remove it
    help: if the documentation should include the empty line include it in the comment
        |
    462 | ///
        |

The comment more seems to be of structural matter and should not be tied
to the function immediately below it. So lets turn it into a normal
non-doc comment.
---
 bindings/rust/libgpiod/src/lib.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/bindings/rust/libgpiod/src/lib.rs b/bindings/rust/libgpiod/src/lib.rs
index fd95ed2ac3fe0bac2042ca58f66263408013457c..c03831bce62b287c08804e2d9d96aea7320dec7c 100644
--- a/bindings/rust/libgpiod/src/lib.rs
+++ b/bindings/rust/libgpiod/src/lib.rs
@@ -454,15 +454,15 @@ pub mod line {
                 GPIOD_EDGE_EVENT_FALLING_EDGE => EdgeKind::Falling,
                 _ => return Err(Error::InvalidEnumValue("EdgeEvent", kind as i32)),
             })
         }
     }
 }
 
-/// Various libgpiod-related functions.
+// Various libgpiod-related functions.
 
 /// Check if the file pointed to by path is a GPIO chip character device.
 ///
 /// Returns true if the file exists and is a GPIO chip character device or a
 /// symbolic link to it.
 pub fn is_gpiochip_device<P: AsRef<Path>>(path: &P) -> bool {
     // Null-terminate the string

-- 
2.47.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH libgpiod 3/3] bindings: rust: libpgiod: fix clippy::empty_line_after_doc_comments lint
  2025-01-02  7:40 [PATCH libgpiod 0/3] bindings: rust: fix some compiler + clippy warnings Erik Schilling
  2025-01-02  7:40 ` [PATCH libgpiod 1/3] bindings: rust: libgpiod: make read_edge_events lifetimes more explicit Erik Schilling
  2025-01-02  7:40 ` [PATCH libgpiod 2/3] bindings: rust: libgpiod: turn standalone doc comment into normal comment Erik Schilling
@ 2025-01-02  7:40 ` Erik Schilling
  2 siblings, 0 replies; 6+ messages in thread
From: Erik Schilling @ 2025-01-02  7:40 UTC (permalink / raw)
  To: Linux-GPIO, Bartosz Golaszewski; +Cc: Erik Schilling, Viresh Kumar, Kent Gibson

clippy warned about this:

    warning: empty line after doc comment
      --> libgpiod/src/event_buffer.rs:15:1
       |
    15 | / /// An iterator over the elements of type `Event`.
    16 | |
       | |_
    17 |   pub struct Events<'a> {
       |   --------------------- the comment documents this struct
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments
       = note: `#[warn(clippy::empty_line_after_doc_comments)]` on by default
       = help: if the empty line is unintentional remove it
---
 bindings/rust/libgpiod/src/event_buffer.rs | 1 -
 1 file changed, 1 deletion(-)

diff --git a/bindings/rust/libgpiod/src/event_buffer.rs b/bindings/rust/libgpiod/src/event_buffer.rs
index 68d6e2f9a875e6b55a2df163cc99a0b9594f51ff..13fa7ba2c8870e0a325e251c073d6d73bb8c4374 100644
--- a/bindings/rust/libgpiod/src/event_buffer.rs
+++ b/bindings/rust/libgpiod/src/event_buffer.rs
@@ -9,15 +9,14 @@ use super::{
     request::{Event, Request},
     Error, OperationType, Result,
 };
 
 /// Line edge events
 ///
 /// An iterator over the elements of type `Event`.
-
 pub struct Events<'a> {
     buffer: &'a mut Buffer,
     read_index: usize,
     len: usize,
 }
 
 impl<'a> Events<'a> {

-- 
2.47.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH libgpiod 2/3] bindings: rust: libgpiod: turn standalone doc comment into normal comment
  2025-01-02  7:40 ` [PATCH libgpiod 2/3] bindings: rust: libgpiod: turn standalone doc comment into normal comment Erik Schilling
@ 2025-01-03 14:32   ` Bartosz Golaszewski
  2025-01-03 14:56     ` Erik Schilling
  0 siblings, 1 reply; 6+ messages in thread
From: Bartosz Golaszewski @ 2025-01-03 14:32 UTC (permalink / raw)
  To: Erik Schilling; +Cc: Linux-GPIO, Viresh Kumar, Kent Gibson

On Thu, Jan 2, 2025 at 8:41 AM Erik Schilling <erik.schilling@linaro.org> wrote:
>
> This was complained about by clippy:
>
>     warning: empty line after doc comment
>        --> libgpiod/src/lib.rs:461:1
>         |
>     461 | / /// Various libgpiod-related functions.
>     462 | |
>         | |_
>     ...
>     467 |   pub fn is_gpiochip_device<P: AsRef<Path>>(path: &P) -> bool {
>         |   ----------------------------------------------------------- the comment documents this function
>         |
>         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments
>         = help: if the empty line is unintentional remove it
>     help: if the documentation should include the empty line include it in the comment
>         |
>     462 | ///
>         |
>
> The comment more seems to be of structural matter and should not be tied
> to the function immediately below it. So lets turn it into a normal
> non-doc comment.
> ---

Hey, commits are missing signed-offs.

Bart

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH libgpiod 2/3] bindings: rust: libgpiod: turn standalone doc comment into normal comment
  2025-01-03 14:32   ` Bartosz Golaszewski
@ 2025-01-03 14:56     ` Erik Schilling
  0 siblings, 0 replies; 6+ messages in thread
From: Erik Schilling @ 2025-01-03 14:56 UTC (permalink / raw)
  To: Bartosz Golaszewski; +Cc: Linux-GPIO, Viresh Kumar, Kent Gibson

On Fri Jan 3, 2025 at 3:32 PM CET, Bartosz Golaszewski wrote:
> On Thu, Jan 2, 2025 at 8:41 AM Erik Schilling <erik.schilling@linaro.org> wrote:
> >
> > This was complained about by clippy:
> >
> >     warning: empty line after doc comment
> >        --> libgpiod/src/lib.rs:461:1
> >         |
> >     461 | / /// Various libgpiod-related functions.
> >     462 | |
> >         | |_
> >     ...
> >     467 |   pub fn is_gpiochip_device<P: AsRef<Path>>(path: &P) -> bool {
> >         |   ----------------------------------------------------------- the comment documents this function
> >         |
> >         = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#empty_line_after_doc_comments
> >         = help: if the empty line is unintentional remove it
> >     help: if the documentation should include the empty line include it in the comment
> >         |
> >     462 | ///
> >         |
> >
> > The comment more seems to be of structural matter and should not be tied
> > to the function immediately below it. So lets turn it into a normal
> > non-doc comment.
> > ---
>
> Hey, commits are missing signed-offs.

Arhg. How did that break?... Will send a v2 with them.

Sorry!

- Erik


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-01-03 14:56 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-02  7:40 [PATCH libgpiod 0/3] bindings: rust: fix some compiler + clippy warnings Erik Schilling
2025-01-02  7:40 ` [PATCH libgpiod 1/3] bindings: rust: libgpiod: make read_edge_events lifetimes more explicit Erik Schilling
2025-01-02  7:40 ` [PATCH libgpiod 2/3] bindings: rust: libgpiod: turn standalone doc comment into normal comment Erik Schilling
2025-01-03 14:32   ` Bartosz Golaszewski
2025-01-03 14:56     ` Erik Schilling
2025-01-02  7:40 ` [PATCH libgpiod 3/3] bindings: rust: libpgiod: fix clippy::empty_line_after_doc_comments lint Erik Schilling

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).