From daf2a6f36eb0f94214003e6cdae70134a69292c5 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 2 Mar 2025 19:52:17 -0800 Subject: [PATCH 1/2] Resolve some elidable_lifetime_names pedantic clippy lint warning: the following explicit lifetimes could be elided: 'a --> src/aserror.rs:47:6 | 47 | impl<'a> Sealed for dyn Error + 'a {} | ^^ ^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names = note: `-W clippy::elidable-lifetime-names` implied by `-W clippy::pedantic` = help: to override `-W clippy::pedantic` add `#[allow(clippy::elidable_lifetime_names)]` help: elide the lifetimes | 47 - impl<'a> Sealed for dyn Error + 'a {} 47 + impl Sealed for dyn Error + '_ {} | warning: the following explicit lifetimes could be elided: 'a --> src/aserror.rs:48:6 | 48 | impl<'a> Sealed for dyn Error + Send + 'a {} | ^^ ^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names help: elide the lifetimes | 48 - impl<'a> Sealed for dyn Error + Send + 'a {} 48 + impl Sealed for dyn Error + Send + '_ {} | warning: the following explicit lifetimes could be elided: 'a --> src/aserror.rs:49:6 | 49 | impl<'a> Sealed for dyn Error + Send + Sync + 'a {} | ^^ ^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names help: elide the lifetimes | 49 - impl<'a> Sealed for dyn Error + Send + Sync + 'a {} 49 + impl Sealed for dyn Error + Send + Sync + '_ {} | warning: the following explicit lifetimes could be elided: 'a --> src/aserror.rs:50:6 | 50 | impl<'a> Sealed for dyn Error + Send + Sync + UnwindSafe + 'a {} | ^^ ^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names help: elide the lifetimes | 50 - impl<'a> Sealed for dyn Error + Send + Sync + UnwindSafe + 'a {} 50 + impl Sealed for dyn Error + Send + Sync + UnwindSafe + '_ {} | --- src/aserror.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/aserror.rs b/src/aserror.rs index d66463a..ac91cc8 100644 --- a/src/aserror.rs +++ b/src/aserror.rs @@ -44,7 +44,7 @@ impl<'a> AsDynError<'a> for dyn Error + Send + Sync + UnwindSafe + 'a { #[doc(hidden)] pub trait Sealed {} impl Sealed for T {} -impl<'a> Sealed for dyn Error + 'a {} -impl<'a> Sealed for dyn Error + Send + 'a {} -impl<'a> Sealed for dyn Error + Send + Sync + 'a {} -impl<'a> Sealed for dyn Error + Send + Sync + UnwindSafe + 'a {} +impl Sealed for dyn Error + '_ {} +impl Sealed for dyn Error + Send + '_ {} +impl Sealed for dyn Error + Send + Sync + '_ {} +impl Sealed for dyn Error + Send + Sync + UnwindSafe + '_ {} From 9f27b766f57f7e3111e6930f7928f4358a95e590 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 2 Mar 2025 19:55:02 -0800 Subject: [PATCH 2/2] Ignore elidable_lifetime_names pedantic clippy lint warning: the following explicit lifetimes could be elided: 'a --> src/var.rs:5:6 | 5 | impl<'a, T: Pointer + ?Sized> Pointer for Var<'a, T> { | ^^ ^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names = note: `-W clippy::elidable-lifetime-names` implied by `-W clippy::pedantic` = help: to override `-W clippy::pedantic` add `#[allow(clippy::elidable_lifetime_names)]` help: elide the lifetimes | 5 - impl<'a, T: Pointer + ?Sized> Pointer for Var<'a, T> { 5 + impl Pointer for Var<'_, T> { | warning: the following explicit lifetimes could be elided: 'a --> tests/test_lints.rs:40:22 | 40 | pub enum MyError<'a> { | ^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names = note: `-W clippy::elidable-lifetime-names` implied by `-W clippy::pedantic` = help: to override `-W clippy::pedantic` add `#[allow(clippy::elidable_lifetime_names)]` help: elide the lifetimes | 40 - pub enum MyError<'a> { 40 + pub enum MyError'_> { | warning: the following explicit lifetimes could be elided: 'a --> tests/test_display.rs:157:14 | 157 | impl<'a> Display for Msg<'a> { | ^^ ^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#elidable_lifetime_names = note: `-W clippy::elidable-lifetime-names` implied by `-W clippy::pedantic` = help: to override `-W clippy::pedantic` add `#[allow(clippy::elidable_lifetime_names)]` help: elide the lifetimes | 157 - impl<'a> Display for Msg<'a> { 157 + impl Display for Msg<'_> { | --- impl/src/expand.rs | 14 ++++++++++++-- src/lib.rs | 1 + tests/test_display.rs | 1 + tests/test_lints.rs | 2 +- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/impl/src/expand.rs b/impl/src/expand.rs index a304632..c693921 100644 --- a/impl/src/expand.rs +++ b/impl/src/expand.rs @@ -181,7 +181,12 @@ fn impl_struct(input: Struct) -> TokenStream { } }; Some(quote! { - #[allow(deprecated, unused_qualifications, clippy::needless_lifetimes)] + #[allow( + deprecated, + unused_qualifications, + clippy::elidable_lifetime_names, + clippy::needless_lifetimes, + )] #from_impl }) }); @@ -451,7 +456,12 @@ fn impl_enum(input: Enum) -> TokenStream { } }; Some(quote! { - #[allow(deprecated, unused_qualifications, clippy::needless_lifetimes)] + #[allow( + deprecated, + unused_qualifications, + clippy::elidable_lifetime_names, + clippy::needless_lifetimes, + )] #from_impl }) }); diff --git a/src/lib.rs b/src/lib.rs index bf8172b..206d3ec 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -259,6 +259,7 @@ #![no_std] #![doc(html_root_url = "https://docs.rs/thiserror/2.0.11")] #![allow( + clippy::elidable_lifetime_names, clippy::module_name_repetitions, clippy::needless_lifetimes, clippy::return_self_not_must_use, diff --git a/tests/test_display.rs b/tests/test_display.rs index 71c4a4a..bb7c923 100644 --- a/tests/test_display.rs +++ b/tests/test_display.rs @@ -1,4 +1,5 @@ #![allow( + clippy::elidable_lifetime_names, clippy::needless_lifetimes, clippy::needless_raw_string_hashes, clippy::trivially_copy_pass_by_ref, diff --git a/tests/test_lints.rs b/tests/test_lints.rs index af5830d..5e2b895 100644 --- a/tests/test_lints.rs +++ b/tests/test_lints.rs @@ -33,7 +33,7 @@ fn test_unused_qualifications() { #[test] fn test_needless_lifetimes() { #![allow(dead_code)] - #![deny(clippy::needless_lifetimes)] + #![deny(clippy::elidable_lifetime_names, clippy::needless_lifetimes)] #[derive(Error, Debug)] #[error("...")]