[PATCH 04/12] rust/common/uninit: Fix Clippy's complaints about lifetime

Zhao Liu posted 12 patches 1 week, 5 days ago
There is a newer version of this series
[PATCH 04/12] rust/common/uninit: Fix Clippy's complaints about lifetime
Posted by Zhao Liu 1 week, 5 days ago
Clippy complains about the following cases and following its suggestion
to fix these warnings.

warning: the following explicit lifetimes could be elided: 'a
  --> common/src/uninit.rs:38:6
   |
38 | impl<'a, T, U> Deref for MaybeUninitField<'a, T, U> {
   |      ^^                                   ^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
   = note: `#[warn(clippy::needless_lifetimes)]` on by default
help: elide the lifetimes
   |
38 - impl<'a, T, U> Deref for MaybeUninitField<'a, T, U> {
38 + impl<T, U> Deref for MaybeUninitField<'_, T, U> {
   |

warning: the following explicit lifetimes could be elided: 'a
  --> common/src/uninit.rs:49:6
   |
49 | impl<'a, T, U> DerefMut for MaybeUninitField<'a, T, U> {
   |      ^^                                      ^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
help: elide the lifetimes
   |
49 - impl<'a, T, U> DerefMut for MaybeUninitField<'a, T, U> {
49 + impl<T, U> DerefMut for MaybeUninitField<'_, T, U> {
   |

warning: `common` (lib) generated 2 warnings (run `cargo clippy --fix --lib -p common` to apply 2 suggestions)

Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
---
 rust/common/src/uninit.rs | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/rust/common/src/uninit.rs b/rust/common/src/uninit.rs
index e7f9fcd2e3fb..8d021b1dfc6e 100644
--- a/rust/common/src/uninit.rs
+++ b/rust/common/src/uninit.rs
@@ -35,7 +35,7 @@ pub const fn parent_mut(f: &mut Self) -> *mut T {
     }
 }
 
-impl<'a, T, U> Deref for MaybeUninitField<'a, T, U> {
+impl<T, U> Deref for MaybeUninitField<'_, T, U> {
     type Target = MaybeUninit<U>;
 
     fn deref(&self) -> &MaybeUninit<U> {
@@ -46,7 +46,7 @@ fn deref(&self) -> &MaybeUninit<U> {
     }
 }
 
-impl<'a, T, U> DerefMut for MaybeUninitField<'a, T, U> {
+impl<T, U> DerefMut for MaybeUninitField<'_, T, U> {
     fn deref_mut(&mut self) -> &mut MaybeUninit<U> {
         // SAFETY: self.child was obtained by dereferencing a valid mutable
         // reference; the content of the memory may be invalid or uninitialized
-- 
2.34.1
Re: [PATCH 04/12] rust/common/uninit: Fix Clippy's complaints about lifetime
Posted by Manos Pitsidianakis 1 week, 5 days ago
On Tue, Sep 16, 2025 at 11:34 AM Zhao Liu <zhao1.liu@intel.com> wrote:
>
> Clippy complains about the following cases and following its suggestion
> to fix these warnings.
>
> warning: the following explicit lifetimes could be elided: 'a
>   --> common/src/uninit.rs:38:6
>    |
> 38 | impl<'a, T, U> Deref for MaybeUninitField<'a, T, U> {
>    |      ^^                                   ^^
>    |
>    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
>    = note: `#[warn(clippy::needless_lifetimes)]` on by default
> help: elide the lifetimes
>    |
> 38 - impl<'a, T, U> Deref for MaybeUninitField<'a, T, U> {
> 38 + impl<T, U> Deref for MaybeUninitField<'_, T, U> {
>    |
>
> warning: the following explicit lifetimes could be elided: 'a
>   --> common/src/uninit.rs:49:6
>    |
> 49 | impl<'a, T, U> DerefMut for MaybeUninitField<'a, T, U> {
>    |      ^^                                      ^^
>    |
>    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
> help: elide the lifetimes
>    |
> 49 - impl<'a, T, U> DerefMut for MaybeUninitField<'a, T, U> {
> 49 + impl<T, U> DerefMut for MaybeUninitField<'_, T, U> {
>    |
>
> warning: `common` (lib) generated 2 warnings (run `cargo clippy --fix --lib -p common` to apply 2 suggestions)
>
> Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
> ---

Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>

>  rust/common/src/uninit.rs | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/rust/common/src/uninit.rs b/rust/common/src/uninit.rs
> index e7f9fcd2e3fb..8d021b1dfc6e 100644
> --- a/rust/common/src/uninit.rs
> +++ b/rust/common/src/uninit.rs
> @@ -35,7 +35,7 @@ pub const fn parent_mut(f: &mut Self) -> *mut T {
>      }
>  }
>
> -impl<'a, T, U> Deref for MaybeUninitField<'a, T, U> {
> +impl<T, U> Deref for MaybeUninitField<'_, T, U> {
>      type Target = MaybeUninit<U>;
>
>      fn deref(&self) -> &MaybeUninit<U> {
> @@ -46,7 +46,7 @@ fn deref(&self) -> &MaybeUninit<U> {
>      }
>  }
>
> -impl<'a, T, U> DerefMut for MaybeUninitField<'a, T, U> {
> +impl<T, U> DerefMut for MaybeUninitField<'_, T, U> {
>      fn deref_mut(&mut self) -> &mut MaybeUninit<U> {
>          // SAFETY: self.child was obtained by dereferencing a valid mutable
>          // reference; the content of the memory may be invalid or uninitialized
> --
> 2.34.1
>