Skip to content

Commit

Permalink
Fix clippy 1.83.0 (#3414)
Browse files Browse the repository at this point in the history
* lang: Fix `clippy::needless_lifetimes`

* idl: Fix `clippy::unnecessary_lazy_evaluations`

* lang: Fix `clippy::needless_lifetimes`

* client: Fix `clippy::needless_lifetimes`
  • Loading branch information
acheroncrypto authored Dec 6, 2024
1 parent a7a23ee commit 7aae0da
Show file tree
Hide file tree
Showing 16 changed files with 44 additions and 50 deletions.
2 changes: 1 addition & 1 deletion client/src/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ pub trait AsSigner {
fn as_signer(&self) -> &dyn Signer;
}

impl<'a> AsSigner for Box<dyn Signer + 'a> {
impl AsSigner for Box<dyn Signer + '_> {
fn as_signer(&self) -> &dyn Signer {
self.as_ref()
}
Expand Down
2 changes: 1 addition & 1 deletion idl/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
))
Expand Down
16 changes: 7 additions & 9 deletions lang/src/accounts/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: AccountSerialize + AccountDeserialize + Clone + fmt::Debug> 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<T: AccountSerialize + AccountDeserialize + Clone + fmt::Debug> 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)
Expand Down Expand Up @@ -369,7 +367,7 @@ impl<'info, T: AccountSerialize + AccountDeserialize + Clone> AccountsClose<'inf
}
}

impl<'info, T: AccountSerialize + AccountDeserialize + Clone> ToAccountMetas for Account<'info, T> {
impl<T: AccountSerialize + AccountDeserialize + Clone> ToAccountMetas for Account<'_, T> {
fn to_account_metas(&self, is_signer: Option<bool>) -> Vec<AccountMeta> {
let is_signer = is_signer.unwrap_or(self.info.is_signer);
let meta = match self.info.is_writable {
Expand All @@ -396,21 +394,21 @@ impl<'info, T: AccountSerialize + AccountDeserialize + Clone> AsRef<AccountInfo<
}
}

impl<'info, T: AccountSerialize + AccountDeserialize + Clone> AsRef<T> for Account<'info, T> {
impl<T: AccountSerialize + AccountDeserialize + Clone> AsRef<T> for Account<'_, T> {
fn as_ref(&self) -> &T {
&self.account
}
}

impl<'a, T: AccountSerialize + AccountDeserialize + Clone> Deref for Account<'a, T> {
impl<T: AccountSerialize + AccountDeserialize + Clone> Deref for Account<'_, T> {
type Target = T;

fn deref(&self) -> &Self::Target {
&(self).account
}
}

impl<'a, T: AccountSerialize + AccountDeserialize + Clone> DerefMut for Account<'a, T> {
impl<T: AccountSerialize + AccountDeserialize + Clone> DerefMut for Account<'_, T> {
fn deref_mut(&mut self) -> &mut Self::Target {
#[cfg(feature = "anchor-debug")]
if !self.info.is_writable {
Expand All @@ -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<T: AccountSerialize + AccountDeserialize + Clone> Key for Account<'_, T> {
fn key(&self) -> Pubkey {
*self.info.key
}
Expand Down
4 changes: 2 additions & 2 deletions lang/src/accounts/account_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>) -> Vec<AccountMeta> {
let is_signer = is_signer.unwrap_or(self.is_signer);
let meta = match self.is_writable {
Expand All @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions lang/src/accounts/account_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: ZeroCopy + Owner + fmt::Debug> fmt::Debug for AccountLoader<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("AccountLoader")
.field("acc_info", &self.acc_info)
Expand Down Expand Up @@ -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<T: ZeroCopy + Owner> ToAccountMetas for AccountLoader<'_, T> {
fn to_account_metas(&self, is_signer: Option<bool>) -> Vec<AccountMeta> {
let is_signer = is_signer.unwrap_or(self.acc_info.is_signer);
let meta = match self.acc_info.is_writable {
Expand All @@ -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<T: ZeroCopy + Owner> Key for AccountLoader<'_, T> {
fn key(&self) -> Pubkey {
*self.acc_info.key
}
Expand Down
4 changes: 2 additions & 2 deletions lang/src/accounts/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> ToAccountMetas for Interface<'_, T> {
fn to_account_metas(&self, is_signer: Option<bool>) -> Vec<AccountMeta> {
self.0.to_account_metas(is_signer)
}
Expand All @@ -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<T: AccountDeserialize> Key for Interface<'_, T> {
fn key(&self) -> Pubkey {
self.0.key()
}
Expand Down
18 changes: 7 additions & 11 deletions lang/src/accounts/interface_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: AccountSerialize + AccountDeserialize + Clone + fmt::Debug> fmt::Debug
for InterfaceAccount<'_, T>
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.account.fmt_with_name("InterfaceAccount", f)
Expand Down Expand Up @@ -276,9 +276,7 @@ impl<'info, T: AccountSerialize + AccountDeserialize + Clone> AccountsClose<'inf
}
}

impl<'info, T: AccountSerialize + AccountDeserialize + Clone> ToAccountMetas
for InterfaceAccount<'info, T>
{
impl<T: AccountSerialize + AccountDeserialize + Clone> ToAccountMetas for InterfaceAccount<'_, T> {
fn to_account_metas(&self, is_signer: Option<bool>) -> Vec<AccountMeta> {
self.account.to_account_metas(is_signer)
}
Expand All @@ -300,29 +298,27 @@ impl<'info, T: AccountSerialize + AccountDeserialize + Clone> AsRef<AccountInfo<
}
}

impl<'info, T: AccountSerialize + AccountDeserialize + Clone> AsRef<T>
for InterfaceAccount<'info, T>
{
impl<T: AccountSerialize + AccountDeserialize + Clone> AsRef<T> for InterfaceAccount<'_, T> {
fn as_ref(&self) -> &T {
self.account.as_ref()
}
}

impl<'a, T: AccountSerialize + AccountDeserialize + Clone> Deref for InterfaceAccount<'a, T> {
impl<T: AccountSerialize + AccountDeserialize + Clone> Deref for InterfaceAccount<'_, T> {
type Target = T;

fn deref(&self) -> &Self::Target {
self.account.deref()
}
}

impl<'a, T: AccountSerialize + AccountDeserialize + Clone> DerefMut for InterfaceAccount<'a, T> {
impl<T: AccountSerialize + AccountDeserialize + Clone> 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<T: AccountSerialize + AccountDeserialize + Clone> Key for InterfaceAccount<'_, T> {
fn key(&self) -> Pubkey {
self.account.key()
}
Expand Down
6 changes: 3 additions & 3 deletions lang/src/accounts/lazy_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ where
pub __fields: Rc<RefCell<Option<Vec<bool>>>>,
}

impl<'info, T> fmt::Debug for LazyAccount<'info, T>
impl<T> fmt::Debug for LazyAccount<'_, T>
where
T: AccountSerialize + Discriminator + Owner + Clone + fmt::Debug,
{
Expand Down Expand Up @@ -296,7 +296,7 @@ where
}
}

impl<'info, T> ToAccountMetas for LazyAccount<'info, T>
impl<T> ToAccountMetas for LazyAccount<'_, T>
where
T: AccountSerialize + Discriminator + Owner + Clone,
{
Expand Down Expand Up @@ -328,7 +328,7 @@ where
}
}

impl<'info, T> Key for LazyAccount<'info, T>
impl<T> Key for LazyAccount<'_, T>
where
T: AccountSerialize + Discriminator + Owner + Clone,
{
Expand Down
6 changes: 3 additions & 3 deletions lang/src/accounts/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub struct Program<'info, T> {
_phantom: PhantomData<T>,
}

impl<'info, T: fmt::Debug> fmt::Debug for Program<'info, T> {
impl<T: fmt::Debug> fmt::Debug for Program<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Program").field("info", &self.info).finish()
}
Expand Down Expand Up @@ -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<T> ToAccountMetas for Program<'_, T> {
fn to_account_metas(&self, is_signer: Option<bool>) -> Vec<AccountMeta> {
let is_signer = is_signer.unwrap_or(self.info.is_signer);
let meta = match self.info.is_writable {
Expand Down Expand Up @@ -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<T: AccountDeserialize> Key for Program<'_, T> {
fn key(&self) -> Pubkey {
*self.info.key
}
Expand Down
4 changes: 2 additions & 2 deletions lang/src/accounts/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>) -> Vec<AccountMeta> {
let is_signer = is_signer.unwrap_or(self.info.is_signer);
let meta = match self.info.is_writable {
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions lang/src/accounts/system_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>) -> Vec<AccountMeta> {
let is_signer = is_signer.unwrap_or(self.info.is_signer);
let meta = match self.info.is_writable {
Expand Down Expand Up @@ -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
}
Expand Down
12 changes: 6 additions & 6 deletions lang/src/accounts/sysvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: solana_program::sysvar::Sysvar + fmt::Debug> fmt::Debug for Sysvar<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Sysvar")
.field("info", &self.info)
Expand All @@ -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<T: solana_program::sysvar::Sysvar> Clone for Sysvar<'_, T> {
fn clone(&self) -> Self {
Self {
info: self.info,
Expand All @@ -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<T: solana_program::sysvar::Sysvar> ToAccountMetas for Sysvar<'_, T> {
fn to_account_metas(&self, _is_signer: Option<bool>) -> Vec<AccountMeta> {
vec![AccountMeta::new_readonly(*self.info.key, false)]
}
Expand All @@ -100,23 +100,23 @@ impl<'info, T: solana_program::sysvar::Sysvar> AsRef<AccountInfo<'info>> for Sys
}
}

impl<'a, T: solana_program::sysvar::Sysvar> Deref for Sysvar<'a, T> {
impl<T: solana_program::sysvar::Sysvar> Deref for Sysvar<'_, T> {
type Target = T;

fn deref(&self) -> &Self::Target {
&self.account
}
}

impl<'a, T: solana_program::sysvar::Sysvar> DerefMut for Sysvar<'a, T> {
impl<T: solana_program::sysvar::Sysvar> DerefMut for Sysvar<'_, T> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.account
}
}

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<T: solana_program::sysvar::Sysvar> Key for Sysvar<'_, T> {
fn key(&self) -> Pubkey {
*self.info.key
}
Expand Down
4 changes: 2 additions & 2 deletions lang/src/accounts/unchecked_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>) -> Vec<AccountMeta> {
let is_signer = is_signer.unwrap_or(self.is_signer);
let meta = match self.is_writable {
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion lang/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> fmt::Debug for Context<'_, '_, '_, '_, T>
where
T: fmt::Debug + Bumps,
{
Expand Down
2 changes: 1 addition & 1 deletion lang/syn/src/parser/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub struct ModuleContext<'krate> {
detail: &'krate ParsedModule,
}

impl<'krate> ModuleContext<'krate> {
impl ModuleContext<'_> {
pub fn items(&self) -> impl Iterator<Item = &syn::Item> {
self.detail.items.iter()
}
Expand Down

0 comments on commit 7aae0da

Please sign in to comment.