add use_self clippy lint (#8325)

This commit is contained in:
Thomas Coratger
2024-05-29 15:14:14 +02:00
committed by GitHub
parent 0cb5358fef
commit 19c529e8df
200 changed files with 1817 additions and 1954 deletions

View File

@ -138,8 +138,8 @@ impl<T: Table> DbCursorRO<T> for CursorMock {
fn walk(&mut self, start_key: Option<T::Key>) -> Result<Walker<'_, T, Self>, DatabaseError> {
let start: IterPairResult<T> = match start_key {
Some(key) => <CursorMock as DbCursorRO<T>>::seek(self, key).transpose(),
None => <CursorMock as DbCursorRO<T>>::first(self).transpose(),
Some(key) => <Self as DbCursorRO<T>>::seek(self, key).transpose(),
None => <Self as DbCursorRO<T>>::first(self).transpose(),
};
Ok(Walker::new(self, start))
@ -160,8 +160,8 @@ impl<T: Table> DbCursorRO<T> for CursorMock {
};
let start: IterPairResult<T> = match start_key {
Some(key) => <CursorMock as DbCursorRO<T>>::seek(self, key).transpose(),
None => <CursorMock as DbCursorRO<T>>::first(self).transpose(),
Some(key) => <Self as DbCursorRO<T>>::seek(self, key).transpose(),
None => <Self as DbCursorRO<T>>::first(self).transpose(),
};
Ok(RangeWalker::new(self, start, end_key))
@ -172,8 +172,8 @@ impl<T: Table> DbCursorRO<T> for CursorMock {
start_key: Option<T::Key>,
) -> Result<ReverseWalker<'_, T, Self>, DatabaseError> {
let start: IterPairResult<T> = match start_key {
Some(key) => <CursorMock as DbCursorRO<T>>::seek(self, key).transpose(),
None => <CursorMock as DbCursorRO<T>>::last(self).transpose(),
Some(key) => <Self as DbCursorRO<T>>::seek(self, key).transpose(),
None => <Self as DbCursorRO<T>>::last(self).transpose(),
};
Ok(ReverseWalker::new(self, start))
}

View File

@ -250,7 +250,7 @@ impl DatabaseEnv {
path: &Path,
kind: DatabaseEnvKind,
args: DatabaseArguments,
) -> Result<DatabaseEnv, DatabaseError> {
) -> Result<Self, DatabaseError> {
let mut inner_env = Environment::builder();
let mode = match kind {
@ -379,7 +379,7 @@ impl DatabaseEnv {
inner_env.set_max_read_transaction_duration(max_read_transaction_duration);
}
let env = DatabaseEnv {
let env = Self {
inner: inner_env.open(path).map_err(|e| DatabaseError::Open(e.into()))?,
metrics: None,
};

View File

@ -156,14 +156,14 @@ impl TransactionMode {
/// Returns the transaction mode as a string.
pub(crate) const fn as_str(&self) -> &'static str {
match self {
TransactionMode::ReadOnly => "read-only",
TransactionMode::ReadWrite => "read-write",
Self::ReadOnly => "read-only",
Self::ReadWrite => "read-write",
}
}
/// Returns `true` if the transaction mode is read-only.
pub(crate) const fn is_read_only(&self) -> bool {
matches!(self, TransactionMode::ReadOnly)
matches!(self, Self::ReadOnly)
}
}
@ -182,15 +182,15 @@ impl TransactionOutcome {
/// Returns the transaction outcome as a string.
pub(crate) const fn as_str(&self) -> &'static str {
match self {
TransactionOutcome::Commit => "commit",
TransactionOutcome::Abort => "abort",
TransactionOutcome::Drop => "drop",
Self::Commit => "commit",
Self::Abort => "abort",
Self::Drop => "drop",
}
}
/// Returns `true` if the transaction outcome is a commit.
pub(crate) const fn is_commit(&self) -> bool {
matches!(self, TransactionOutcome::Commit)
matches!(self, Self::Commit)
}
}
@ -221,15 +221,15 @@ impl Operation {
/// Returns the operation as a string.
pub(crate) const fn as_str(&self) -> &'static str {
match self {
Operation::Get => "get",
Operation::Put => "put",
Operation::Delete => "delete",
Operation::CursorUpsert => "cursor-upsert",
Operation::CursorInsert => "cursor-insert",
Operation::CursorAppend => "cursor-append",
Operation::CursorAppendDup => "cursor-append-dup",
Operation::CursorDeleteCurrent => "cursor-delete-current",
Operation::CursorDeleteCurrentDuplicates => "cursor-delete-current-duplicates",
Self::Get => "get",
Self::Put => "put",
Self::Delete => "delete",
Self::CursorUpsert => "cursor-upsert",
Self::CursorInsert => "cursor-insert",
Self::CursorAppend => "cursor-append",
Self::CursorAppendDup => "cursor-append-dup",
Self::CursorDeleteCurrent => "cursor-delete-current",
Self::CursorDeleteCurrentDuplicates => "cursor-delete-current-duplicates",
}
}
}
@ -250,10 +250,10 @@ impl Labels {
/// Converts each label variant into its corresponding string representation.
pub(crate) fn as_str(&self) -> &'static str {
match self {
Labels::Table => "table",
Labels::TransactionMode => "mode",
Labels::TransactionOutcome => "outcome",
Labels::Operation => "operation",
Self::Table => "table",
Self::TransactionMode => "mode",
Self::TransactionOutcome => "outcome",
Self::Operation => "operation",
}
}
}

View File

@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
pub struct IntegerListInput(pub Vec<u64>);
impl From<IntegerListInput> for IntegerList {
fn from(list: IntegerListInput) -> IntegerList {
fn from(list: IntegerListInput) -> Self {
let mut v = list.0;
// Empty lists are not supported by `IntegerList`, so we want to skip these cases.

View File

@ -92,7 +92,7 @@ impl BlockNumberAddress {
impl From<(BlockNumber, Address)> for BlockNumberAddress {
fn from(tpl: (u64, Address)) -> Self {
BlockNumberAddress(tpl)
Self(tpl)
}
}
@ -117,7 +117,7 @@ impl Decode for BlockNumberAddress {
let num = u64::from_be_bytes(value[..8].try_into().map_err(|_| DatabaseError::Decode)?);
let hash = Address::from_slice(&value[8..]);
Ok(BlockNumberAddress((num, hash)))
Ok(Self((num, hash)))
}
}
@ -150,7 +150,7 @@ impl Decode for AddressStorageKey {
let address = Address::from_slice(&value[..20]);
let storage_key = StorageKey::from_slice(&value[20..]);
Ok(AddressStorageKey((address, storage_key)))
Ok(Self((address, storage_key)))
}
}

View File

@ -19,6 +19,6 @@ impl Compress for IntegerList {
impl Decompress for IntegerList {
fn decompress<B: AsRef<[u8]>>(value: B) -> Result<Self, DatabaseError> {
IntegerList::from_bytes(value.as_ref()).map_err(|_| DatabaseError::Decode)
Self::from_bytes(value.as_ref()).map_err(|_| DatabaseError::Decode)
}
}

View File

@ -51,7 +51,7 @@ macro_rules! impl_uints {
impl_uints!(u64, u32, u16, u8);
impl Encode for Vec<u8> {
type Encoded = Vec<u8>;
type Encoded = Self;
fn encode(self) -> Self::Encoded {
self
@ -74,7 +74,7 @@ impl Encode for Address {
impl Decode for Address {
fn decode<B: AsRef<[u8]>>(value: B) -> Result<Self, DatabaseError> {
Ok(Address::from_slice(value.as_ref()))
Ok(Self::from_slice(value.as_ref()))
}
}
@ -88,7 +88,7 @@ impl Encode for B256 {
impl Decode for B256 {
fn decode<B: AsRef<[u8]>>(value: B) -> Result<Self, DatabaseError> {
Ok(B256::new(value.as_ref().try_into().map_err(|_| DatabaseError::Decode)?))
Ok(Self::new(value.as_ref().try_into().map_err(|_| DatabaseError::Decode)?))
}
}
@ -102,7 +102,7 @@ impl Encode for String {
impl Decode for String {
fn decode<B: AsRef<[u8]>>(value: B) -> Result<Self, DatabaseError> {
String::from_utf8(value.as_ref().to_vec()).map_err(|_| DatabaseError::Decode)
Self::from_utf8(value.as_ref().to_vec()).map_err(|_| DatabaseError::Decode)
}
}

View File

@ -26,8 +26,8 @@ pub struct ShardedKey<T> {
pub highest_block_number: BlockNumber,
}
impl<T> AsRef<ShardedKey<T>> for ShardedKey<T> {
fn as_ref(&self) -> &ShardedKey<T> {
impl<T> AsRef<Self> for ShardedKey<T> {
fn as_ref(&self) -> &Self {
self
}
}
@ -35,7 +35,7 @@ impl<T> AsRef<ShardedKey<T>> for ShardedKey<T> {
impl<T> ShardedKey<T> {
/// Creates a new `ShardedKey<T>`.
pub fn new(key: T, highest_block_number: BlockNumber) -> Self {
ShardedKey { key, highest_block_number }
Self { key, highest_block_number }
}
/// Creates a new key with the highest block number set to maximum.
@ -73,7 +73,7 @@ where
);
let key = T::decode(&value[..tx_num_index])?;
Ok(ShardedKey::new(key, highest_tx_number))
Ok(Self::new(key, highest_tx_number))
}
}

View File

@ -77,7 +77,7 @@ impl<K: Key> RawKey<K> {
impl<K: Key> From<K> for RawKey<K> {
fn from(key: K) -> Self {
RawKey::new(key)
Self::new(key)
}
}
@ -142,7 +142,7 @@ impl<V: Value> RawValue<V> {
impl<V: Value> From<V> for RawValue<V> {
fn from(value: V) -> Self {
RawValue::new(value)
Self::new(value)
}
}