Add missing_const_for_fn clippy lint (#8498)

This commit is contained in:
Thomas Coratger
2024-05-30 11:50:03 +02:00
committed by GitHub
parent 99068198db
commit 3d3f52b2a4
255 changed files with 834 additions and 804 deletions

View File

@ -44,16 +44,16 @@ macro_rules! impl_iai_callgrind_inner {
}
#[allow(dead_code)]
pub fn $seqread() {}
pub const fn $seqread() {}
#[allow(dead_code)]
pub fn $randread() {}
pub const fn $randread() {}
#[allow(dead_code)]
pub fn $seqwrite() {}
pub const fn $seqwrite() {}
#[allow(dead_code)]
pub fn $randwrite() {}
pub const fn $randwrite() {}
library_benchmark_group!(

View File

@ -50,12 +50,12 @@ pub struct DatabaseMetadataValue {
impl DatabaseMetadataValue {
/// Creates a new [DatabaseMetadataValue] with the given freelist size.
pub fn new(freelist_size: Option<usize>) -> Self {
pub const fn new(freelist_size: Option<usize>) -> Self {
Self { freelist_size }
}
/// Returns the freelist size, if available.
pub fn freelist_size(&self) -> Option<usize> {
pub const fn freelist_size(&self) -> Option<usize> {
self.freelist_size
}
}

View File

@ -52,7 +52,7 @@ pub enum DatabaseEnvKind {
impl DatabaseEnvKind {
/// Returns `true` if the environment is read-write.
pub fn is_rw(&self) -> bool {
pub const fn is_rw(&self) -> bool {
matches!(self, Self::RW)
}
}
@ -91,7 +91,7 @@ pub struct DatabaseArguments {
impl DatabaseArguments {
/// Create new database arguments with given client version.
pub fn new(client_version: ClientVersion) -> Self {
pub const fn new(client_version: ClientVersion) -> Self {
Self {
client_version,
log_level: None,
@ -101,13 +101,13 @@ impl DatabaseArguments {
}
/// Set the log level.
pub fn with_log_level(mut self, log_level: Option<LogLevel>) -> Self {
pub const fn with_log_level(mut self, log_level: Option<LogLevel>) -> Self {
self.log_level = log_level;
self
}
/// Set the maximum duration of a read transaction.
pub fn with_max_read_transaction_duration(
pub const fn with_max_read_transaction_duration(
mut self,
max_read_transaction_duration: Option<MaxReadTransactionDuration>,
) -> Self {
@ -116,13 +116,13 @@ impl DatabaseArguments {
}
/// Set the mdbx exclusive flag.
pub fn with_exclusive(mut self, exclusive: Option<bool>) -> Self {
pub const fn with_exclusive(mut self, exclusive: Option<bool>) -> Self {
self.exclusive = exclusive;
self
}
/// Returns the client version if any.
pub fn client_version(&self) -> &ClientVersion {
pub const fn client_version(&self) -> &ClientVersion {
&self.client_version
}
}

View File

@ -45,7 +45,7 @@ pub struct Tx<K: TransactionKind> {
impl<K: TransactionKind> Tx<K> {
/// Creates new `Tx` object with a `RO` or `RW` transaction.
#[inline]
pub fn new(inner: Transaction<K>) -> Self {
pub const fn new(inner: Transaction<K>) -> Self {
Self::new_inner(inner, None)
}
@ -68,7 +68,7 @@ impl<K: TransactionKind> Tx<K> {
}
#[inline]
fn new_inner(inner: Transaction<K>, metrics_handler: Option<MetricsHandler<K>>) -> Self {
const fn new_inner(inner: Transaction<K>, metrics_handler: Option<MetricsHandler<K>>) -> Self {
// NOTE: These constants are needed to initialize `OnceCell` at compile-time, as array
// initialization is not allowed with non-Copy types, and `const { }` blocks are not stable
// yet.

View File

@ -248,7 +248,7 @@ enum Labels {
impl Labels {
/// Converts each label variant into its corresponding string representation.
pub(crate) fn as_str(&self) -> &'static str {
pub(crate) const fn as_str(&self) -> &'static str {
match self {
Self::Table => "table",
Self::TransactionMode => "mode",

View File

@ -75,17 +75,17 @@ impl BlockNumberAddress {
}
/// Return the block number
pub fn block_number(&self) -> BlockNumber {
pub const fn block_number(&self) -> BlockNumber {
self.0 .0
}
/// Return the address
pub fn address(&self) -> Address {
pub const fn address(&self) -> Address {
self.0 .1
}
/// Consumes `Self` and returns [`BlockNumber`], [`Address`]
pub fn take(self) -> (BlockNumber, Address) {
pub const fn take(self) -> (BlockNumber, Address) {
(self.0 .0, self.0 .1)
}
}

View File

@ -28,14 +28,14 @@ pub struct StoredBlockBodyIndices {
impl StoredBlockBodyIndices {
/// Return the range of transaction ids for this block.
pub fn tx_num_range(&self) -> Range<TxNumber> {
pub const fn tx_num_range(&self) -> Range<TxNumber> {
self.first_tx_num..self.first_tx_num + self.tx_count
}
/// Return the index of last transaction in this block unless the block
/// is empty in which case it refers to the last transaction in a previous
/// non-empty block
pub fn last_tx_num(&self) -> TxNumber {
pub const fn last_tx_num(&self) -> TxNumber {
self.first_tx_num.saturating_add(self.tx_count).saturating_sub(1)
}
@ -43,24 +43,24 @@ impl StoredBlockBodyIndices {
///
/// Caution: If the block is empty, this is the number of the first transaction
/// in the next non-empty block.
pub fn first_tx_num(&self) -> TxNumber {
pub const fn first_tx_num(&self) -> TxNumber {
self.first_tx_num
}
/// Return the index of the next transaction after this block.
pub fn next_tx_num(&self) -> TxNumber {
pub const fn next_tx_num(&self) -> TxNumber {
self.first_tx_num + self.tx_count
}
/// Return a flag whether the block is empty
pub fn is_empty(&self) -> bool {
pub const fn is_empty(&self) -> bool {
self.tx_count == 0
}
/// Return number of transaction inside block
///
/// NOTE: This is not the same as the number of transitions.
pub fn tx_count(&self) -> NumTransactions {
pub const fn tx_count(&self) -> NumTransactions {
self.tx_count
}
}

View File

@ -34,13 +34,13 @@ impl<T> AsRef<Self> for ShardedKey<T> {
impl<T> ShardedKey<T> {
/// Creates a new `ShardedKey<T>`.
pub fn new(key: T, highest_block_number: BlockNumber) -> Self {
pub const fn new(key: T, highest_block_number: BlockNumber) -> Self {
Self { key, highest_block_number }
}
/// Creates a new key with the highest block number set to maximum.
/// This is useful when we want to search the last value for a given key.
pub fn last(key: T) -> Self {
pub const fn last(key: T) -> Self {
Self { key, highest_block_number: u64::MAX }
}
}

View File

@ -32,13 +32,17 @@ pub struct StorageShardedKey {
impl StorageShardedKey {
/// Creates a new `StorageShardedKey`.
pub fn new(address: Address, storage_key: B256, highest_block_number: BlockNumber) -> Self {
pub const fn new(
address: Address,
storage_key: B256,
highest_block_number: BlockNumber,
) -> Self {
Self { address, sharded_key: ShardedKey { key: storage_key, highest_block_number } }
}
/// Creates a new key with the highest block number set to maximum.
/// This is useful when we want to search the last value for a given key.
pub fn last(address: Address, storage_key: B256) -> Self {
pub const fn last(address: Address, storage_key: B256) -> Self {
Self {
address,
sharded_key: ShardedKey { key: storage_key, highest_block_number: u64::MAX },

View File

@ -65,7 +65,7 @@ impl<K: Key> RawKey<K> {
}
/// Returns the raw key as seen on the database.
pub fn raw_key(&self) -> &Vec<u8> {
pub const fn raw_key(&self) -> &Vec<u8> {
&self.key
}