From 7aae0daa1a85e9105587c5509ec1c81a3afbbc88 Mon Sep 17 00:00:00 2001 From: acheron <98934430+acheroncrypto@users.noreply.github.com> Date: Fri, 6 Dec 2024 10:44:37 +0100 Subject: [PATCH] Fix `clippy 1.83.0` (#3414) * lang: Fix `clippy::needless_lifetimes` * idl: Fix `clippy::unnecessary_lazy_evaluations` * lang: Fix `clippy::needless_lifetimes` * client: Fix `clippy::needless_lifetimes` --- client/src/blocking.rs | 2 +- client/src/lib.rs | 2 +- idl/src/convert.rs | 2 +- lang/src/accounts/account.rs | 16 +++++++--------- lang/src/accounts/account_info.rs | 4 ++-- lang/src/accounts/account_loader.rs | 6 +++--- lang/src/accounts/interface.rs | 4 ++-- lang/src/accounts/interface_account.rs | 18 +++++++----------- lang/src/accounts/lazy_account.rs | 6 +++--- lang/src/accounts/program.rs | 6 +++--- lang/src/accounts/signer.rs | 4 ++-- lang/src/accounts/system_account.rs | 4 ++-- lang/src/accounts/sysvar.rs | 12 ++++++------ lang/src/accounts/unchecked_account.rs | 4 ++-- lang/src/context.rs | 2 +- lang/syn/src/parser/context.rs | 2 +- 16 files changed, 44 insertions(+), 50 deletions(-) diff --git a/client/src/blocking.rs b/client/src/blocking.rs index a0522d7ed0..5de6cdba41 100644 --- a/client/src/blocking.rs +++ b/client/src/blocking.rs @@ -19,7 +19,7 @@ use tokio::{ sync::RwLock, }; -impl<'a> EventUnsubscriber<'a> { +impl EventUnsubscriber<'_> { /// Unsubscribe gracefully. pub fn unsubscribe(self) { self.runtime_handle.block_on(self.unsubscribe_internal()) diff --git a/client/src/lib.rs b/client/src/lib.rs index eca609ed40..35f5849e98 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -497,7 +497,7 @@ pub trait AsSigner { fn as_signer(&self) -> &dyn Signer; } -impl<'a> AsSigner for Box { +impl AsSigner for Box { fn as_signer(&self) -> &dyn Signer { self.as_ref() } diff --git a/idl/src/convert.rs b/idl/src/convert.rs index 0aeef4c795..01edc14252 100644 --- a/idl/src/convert.rs +++ b/idl/src/convert.rs @@ -431,7 +431,7 @@ mod legacy { fn from(value: IdlTypeDefinitionTy) -> Self { match value { IdlTypeDefinitionTy::Struct { fields } => Self::Struct { - fields: fields.is_empty().then(|| None).unwrap_or_else(|| { + fields: fields.is_empty().then_some(None).unwrap_or_else(|| { Some(t::IdlDefinedFields::Named( fields.into_iter().map(Into::into).collect(), )) diff --git a/lang/src/accounts/account.rs b/lang/src/accounts/account.rs index 0ba1e974b0..a8308de3fd 100644 --- a/lang/src/accounts/account.rs +++ b/lang/src/accounts/account.rs @@ -229,15 +229,13 @@ pub struct Account<'info, T: AccountSerialize + AccountDeserialize + Clone> { info: &'info AccountInfo<'info>, } -impl<'info, T: AccountSerialize + AccountDeserialize + Clone + fmt::Debug> fmt::Debug - for Account<'info, T> -{ +impl fmt::Debug for Account<'_, T> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.fmt_with_name("Account", f) } } -impl<'info, T: AccountSerialize + AccountDeserialize + Clone + fmt::Debug> Account<'info, T> { +impl Account<'_, T> { pub(crate) fn fmt_with_name(&self, name: &str, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct(name) .field("account", &self.account) @@ -369,7 +367,7 @@ impl<'info, T: AccountSerialize + AccountDeserialize + Clone> AccountsClose<'inf } } -impl<'info, T: AccountSerialize + AccountDeserialize + Clone> ToAccountMetas for Account<'info, T> { +impl ToAccountMetas for Account<'_, T> { fn to_account_metas(&self, is_signer: Option) -> Vec { let is_signer = is_signer.unwrap_or(self.info.is_signer); let meta = match self.info.is_writable { @@ -396,13 +394,13 @@ impl<'info, T: AccountSerialize + AccountDeserialize + Clone> AsRef AsRef for Account<'info, T> { +impl AsRef for Account<'_, T> { fn as_ref(&self) -> &T { &self.account } } -impl<'a, T: AccountSerialize + AccountDeserialize + Clone> Deref for Account<'a, T> { +impl Deref for Account<'_, T> { type Target = T; fn deref(&self) -> &Self::Target { @@ -410,7 +408,7 @@ impl<'a, T: AccountSerialize + AccountDeserialize + Clone> Deref for Account<'a, } } -impl<'a, T: AccountSerialize + AccountDeserialize + Clone> DerefMut for Account<'a, T> { +impl DerefMut for Account<'_, T> { fn deref_mut(&mut self) -> &mut Self::Target { #[cfg(feature = "anchor-debug")] if !self.info.is_writable { @@ -421,7 +419,7 @@ impl<'a, T: AccountSerialize + AccountDeserialize + Clone> DerefMut for Account< } } -impl<'info, T: AccountSerialize + AccountDeserialize + Clone> Key for Account<'info, T> { +impl Key for Account<'_, T> { fn key(&self) -> Pubkey { *self.info.key } diff --git a/lang/src/accounts/account_info.rs b/lang/src/accounts/account_info.rs index 56922a78a5..872d5cd021 100644 --- a/lang/src/accounts/account_info.rs +++ b/lang/src/accounts/account_info.rs @@ -26,7 +26,7 @@ impl<'info, B> Accounts<'info, B> for AccountInfo<'info> { } } -impl<'info> ToAccountMetas for AccountInfo<'info> { +impl ToAccountMetas for AccountInfo<'_> { fn to_account_metas(&self, is_signer: Option) -> Vec { let is_signer = is_signer.unwrap_or(self.is_signer); let meta = match self.is_writable { @@ -45,7 +45,7 @@ impl<'info> ToAccountInfos<'info> for AccountInfo<'info> { impl<'info> AccountsExit<'info> for AccountInfo<'info> {} -impl<'info> Key for AccountInfo<'info> { +impl Key for AccountInfo<'_> { fn key(&self) -> Pubkey { *self.key } diff --git a/lang/src/accounts/account_loader.rs b/lang/src/accounts/account_loader.rs index a7392299e6..d9b172b28f 100644 --- a/lang/src/accounts/account_loader.rs +++ b/lang/src/accounts/account_loader.rs @@ -98,7 +98,7 @@ pub struct AccountLoader<'info, T: ZeroCopy + Owner> { phantom: PhantomData<&'info T>, } -impl<'info, T: ZeroCopy + Owner + fmt::Debug> fmt::Debug for AccountLoader<'info, T> { +impl fmt::Debug for AccountLoader<'_, T> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("AccountLoader") .field("acc_info", &self.acc_info) @@ -260,7 +260,7 @@ impl<'info, T: ZeroCopy + Owner> AccountsClose<'info> for AccountLoader<'info, T } } -impl<'info, T: ZeroCopy + Owner> ToAccountMetas for AccountLoader<'info, T> { +impl ToAccountMetas for AccountLoader<'_, T> { fn to_account_metas(&self, is_signer: Option) -> Vec { let is_signer = is_signer.unwrap_or(self.acc_info.is_signer); let meta = match self.acc_info.is_writable { @@ -283,7 +283,7 @@ impl<'info, T: ZeroCopy + Owner> ToAccountInfos<'info> for AccountLoader<'info, } } -impl<'info, T: ZeroCopy + Owner> Key for AccountLoader<'info, T> { +impl Key for AccountLoader<'_, T> { fn key(&self) -> Pubkey { *self.acc_info.key } diff --git a/lang/src/accounts/interface.rs b/lang/src/accounts/interface.rs index b5cf1f181d..8fe9254958 100644 --- a/lang/src/accounts/interface.rs +++ b/lang/src/accounts/interface.rs @@ -123,7 +123,7 @@ impl<'info, B, T: CheckId> Accounts<'info, B> for Interface<'info, T> { } } -impl<'info, T> ToAccountMetas for Interface<'info, T> { +impl ToAccountMetas for Interface<'_, T> { fn to_account_metas(&self, is_signer: Option) -> Vec { self.0.to_account_metas(is_signer) } @@ -137,7 +137,7 @@ impl<'info, T> ToAccountInfos<'info> for Interface<'info, T> { impl<'info, T: AccountDeserialize> AccountsExit<'info> for Interface<'info, T> {} -impl<'info, T: AccountDeserialize> Key for Interface<'info, T> { +impl Key for Interface<'_, T> { fn key(&self) -> Pubkey { self.0.key() } diff --git a/lang/src/accounts/interface_account.rs b/lang/src/accounts/interface_account.rs index fd2a6e1695..51efd13e60 100644 --- a/lang/src/accounts/interface_account.rs +++ b/lang/src/accounts/interface_account.rs @@ -165,8 +165,8 @@ pub struct InterfaceAccount<'info, T: AccountSerialize + AccountDeserialize + Cl owner: Pubkey, } -impl<'info, T: AccountSerialize + AccountDeserialize + Clone + fmt::Debug> fmt::Debug - for InterfaceAccount<'info, T> +impl fmt::Debug + for InterfaceAccount<'_, T> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.account.fmt_with_name("InterfaceAccount", f) @@ -276,9 +276,7 @@ impl<'info, T: AccountSerialize + AccountDeserialize + Clone> AccountsClose<'inf } } -impl<'info, T: AccountSerialize + AccountDeserialize + Clone> ToAccountMetas - for InterfaceAccount<'info, T> -{ +impl ToAccountMetas for InterfaceAccount<'_, T> { fn to_account_metas(&self, is_signer: Option) -> Vec { self.account.to_account_metas(is_signer) } @@ -300,15 +298,13 @@ impl<'info, T: AccountSerialize + AccountDeserialize + Clone> AsRef AsRef - for InterfaceAccount<'info, T> -{ +impl AsRef for InterfaceAccount<'_, T> { fn as_ref(&self) -> &T { self.account.as_ref() } } -impl<'a, T: AccountSerialize + AccountDeserialize + Clone> Deref for InterfaceAccount<'a, T> { +impl Deref for InterfaceAccount<'_, T> { type Target = T; fn deref(&self) -> &Self::Target { @@ -316,13 +312,13 @@ impl<'a, T: AccountSerialize + AccountDeserialize + Clone> Deref for InterfaceAc } } -impl<'a, T: AccountSerialize + AccountDeserialize + Clone> DerefMut for InterfaceAccount<'a, T> { +impl DerefMut for InterfaceAccount<'_, T> { fn deref_mut(&mut self) -> &mut Self::Target { self.account.deref_mut() } } -impl<'info, T: AccountSerialize + AccountDeserialize + Clone> Key for InterfaceAccount<'info, T> { +impl Key for InterfaceAccount<'_, T> { fn key(&self) -> Pubkey { self.account.key() } diff --git a/lang/src/accounts/lazy_account.rs b/lang/src/accounts/lazy_account.rs index 1308cbd14b..8ac3030222 100644 --- a/lang/src/accounts/lazy_account.rs +++ b/lang/src/accounts/lazy_account.rs @@ -185,7 +185,7 @@ where pub __fields: Rc>>>, } -impl<'info, T> fmt::Debug for LazyAccount<'info, T> +impl fmt::Debug for LazyAccount<'_, T> where T: AccountSerialize + Discriminator + Owner + Clone + fmt::Debug, { @@ -296,7 +296,7 @@ where } } -impl<'info, T> ToAccountMetas for LazyAccount<'info, T> +impl ToAccountMetas for LazyAccount<'_, T> where T: AccountSerialize + Discriminator + Owner + Clone, { @@ -328,7 +328,7 @@ where } } -impl<'info, T> Key for LazyAccount<'info, T> +impl Key for LazyAccount<'_, T> where T: AccountSerialize + Discriminator + Owner + Clone, { diff --git a/lang/src/accounts/program.rs b/lang/src/accounts/program.rs index 1058b62a58..701edb16a6 100644 --- a/lang/src/accounts/program.rs +++ b/lang/src/accounts/program.rs @@ -80,7 +80,7 @@ pub struct Program<'info, T> { _phantom: PhantomData, } -impl<'info, T: fmt::Debug> fmt::Debug for Program<'info, T> { +impl fmt::Debug for Program<'_, T> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Program").field("info", &self.info).finish() } @@ -157,7 +157,7 @@ impl<'info, B, T: Id> Accounts<'info, B> for Program<'info, T> { } } -impl<'info, T> ToAccountMetas for Program<'info, T> { +impl ToAccountMetas for Program<'_, T> { fn to_account_metas(&self, is_signer: Option) -> Vec { let is_signer = is_signer.unwrap_or(self.info.is_signer); let meta = match self.info.is_writable { @@ -190,7 +190,7 @@ impl<'info, T> Deref for Program<'info, T> { impl<'info, T: AccountDeserialize> AccountsExit<'info> for Program<'info, T> {} -impl<'info, T: AccountDeserialize> Key for Program<'info, T> { +impl Key for Program<'_, T> { fn key(&self) -> Pubkey { *self.info.key } diff --git a/lang/src/accounts/signer.rs b/lang/src/accounts/signer.rs index e85ea34dcb..34a4ca603d 100644 --- a/lang/src/accounts/signer.rs +++ b/lang/src/accounts/signer.rs @@ -74,7 +74,7 @@ impl<'info, B> Accounts<'info, B> for Signer<'info> { impl<'info> AccountsExit<'info> for Signer<'info> {} -impl<'info> ToAccountMetas for Signer<'info> { +impl ToAccountMetas for Signer<'_> { fn to_account_metas(&self, is_signer: Option) -> Vec { let is_signer = is_signer.unwrap_or(self.info.is_signer); let meta = match self.info.is_writable { @@ -105,7 +105,7 @@ impl<'info> Deref for Signer<'info> { } } -impl<'info> Key for Signer<'info> { +impl Key for Signer<'_> { fn key(&self) -> Pubkey { *self.info.key } diff --git a/lang/src/accounts/system_account.rs b/lang/src/accounts/system_account.rs index ae895c864a..3e93ebb31a 100644 --- a/lang/src/accounts/system_account.rs +++ b/lang/src/accounts/system_account.rs @@ -49,7 +49,7 @@ impl<'info, B> Accounts<'info, B> for SystemAccount<'info> { impl<'info> AccountsExit<'info> for SystemAccount<'info> {} -impl<'info> ToAccountMetas for SystemAccount<'info> { +impl ToAccountMetas for SystemAccount<'_> { fn to_account_metas(&self, is_signer: Option) -> Vec { let is_signer = is_signer.unwrap_or(self.info.is_signer); let meta = match self.info.is_writable { @@ -80,7 +80,7 @@ impl<'info> Deref for SystemAccount<'info> { } } -impl<'info> Key for SystemAccount<'info> { +impl Key for SystemAccount<'_> { fn key(&self) -> Pubkey { *self.info.key } diff --git a/lang/src/accounts/sysvar.rs b/lang/src/accounts/sysvar.rs index 094171c038..8d81f5ba16 100644 --- a/lang/src/accounts/sysvar.rs +++ b/lang/src/accounts/sysvar.rs @@ -35,7 +35,7 @@ pub struct Sysvar<'info, T: solana_program::sysvar::Sysvar> { account: T, } -impl<'info, T: solana_program::sysvar::Sysvar + fmt::Debug> fmt::Debug for Sysvar<'info, T> { +impl fmt::Debug for Sysvar<'_, T> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Sysvar") .field("info", &self.info) @@ -56,7 +56,7 @@ impl<'info, T: solana_program::sysvar::Sysvar> Sysvar<'info, T> { } } -impl<'info, T: solana_program::sysvar::Sysvar> Clone for Sysvar<'info, T> { +impl Clone for Sysvar<'_, T> { fn clone(&self) -> Self { Self { info: self.info, @@ -82,7 +82,7 @@ impl<'info, B, T: solana_program::sysvar::Sysvar> Accounts<'info, B> for Sysvar< } } -impl<'info, T: solana_program::sysvar::Sysvar> ToAccountMetas for Sysvar<'info, T> { +impl ToAccountMetas for Sysvar<'_, T> { fn to_account_metas(&self, _is_signer: Option) -> Vec { vec![AccountMeta::new_readonly(*self.info.key, false)] } @@ -100,7 +100,7 @@ impl<'info, T: solana_program::sysvar::Sysvar> AsRef> for Sys } } -impl<'a, T: solana_program::sysvar::Sysvar> Deref for Sysvar<'a, T> { +impl Deref for Sysvar<'_, T> { type Target = T; fn deref(&self) -> &Self::Target { @@ -108,7 +108,7 @@ impl<'a, T: solana_program::sysvar::Sysvar> Deref for Sysvar<'a, T> { } } -impl<'a, T: solana_program::sysvar::Sysvar> DerefMut for Sysvar<'a, T> { +impl DerefMut for Sysvar<'_, T> { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.account } @@ -116,7 +116,7 @@ impl<'a, T: solana_program::sysvar::Sysvar> DerefMut for Sysvar<'a, T> { impl<'info, T: solana_program::sysvar::Sysvar> AccountsExit<'info> for Sysvar<'info, T> {} -impl<'info, T: solana_program::sysvar::Sysvar> Key for Sysvar<'info, T> { +impl Key for Sysvar<'_, T> { fn key(&self) -> Pubkey { *self.info.key } diff --git a/lang/src/accounts/unchecked_account.rs b/lang/src/accounts/unchecked_account.rs index 6ae4398b57..f08092bda4 100644 --- a/lang/src/accounts/unchecked_account.rs +++ b/lang/src/accounts/unchecked_account.rs @@ -37,7 +37,7 @@ impl<'info, B> Accounts<'info, B> for UncheckedAccount<'info> { } } -impl<'info> ToAccountMetas for UncheckedAccount<'info> { +impl ToAccountMetas for UncheckedAccount<'_> { fn to_account_metas(&self, is_signer: Option) -> Vec { let is_signer = is_signer.unwrap_or(self.is_signer); let meta = match self.is_writable { @@ -70,7 +70,7 @@ impl<'info> Deref for UncheckedAccount<'info> { } } -impl<'info> Key for UncheckedAccount<'info> { +impl Key for UncheckedAccount<'_> { fn key(&self) -> Pubkey { *self.0.key } diff --git a/lang/src/context.rs b/lang/src/context.rs index 6c2b7dfe92..5f7f7eda43 100644 --- a/lang/src/context.rs +++ b/lang/src/context.rs @@ -36,7 +36,7 @@ pub struct Context<'a, 'b, 'c, 'info, T: Bumps> { pub bumps: T::Bumps, } -impl<'a, 'b, 'c, 'info, T> fmt::Debug for Context<'a, 'b, 'c, 'info, T> +impl fmt::Debug for Context<'_, '_, '_, '_, T> where T: fmt::Debug + Bumps, { diff --git a/lang/syn/src/parser/context.rs b/lang/syn/src/parser/context.rs index 00a0937d22..6ec4dc36d9 100644 --- a/lang/syn/src/parser/context.rs +++ b/lang/syn/src/parser/context.rs @@ -94,7 +94,7 @@ pub struct ModuleContext<'krate> { detail: &'krate ParsedModule, } -impl<'krate> ModuleContext<'krate> { +impl ModuleContext<'_> { pub fn items(&self) -> impl Iterator { self.detail.items.iter() }