Message ID | 20250103-lifetime-fix-v2-1-63902dc8cae1@linaro.org |
---|---|
State | New |
Headers | show |
Series | bindings: rust: fix some compiler + clippy warnings | expand |
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 {
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/ Signed-off-by: Erik Schilling <erik.schilling@linaro.org> --- bindings/rust/libgpiod/src/line_request.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)