From 2d2fb059e75c4743f48e0d28e75fe137305ae47a Mon Sep 17 00:00:00 2001 From: Thomas Coratger <60488569+tcoratger@users.noreply.github.com> Date: Wed, 22 May 2024 12:40:09 +0200 Subject: [PATCH] Add warn on `missing_const_for_fn` clippy (#1100) * add missing_const_for_fn to cargo toml * update clippy --- Cargo.toml | 2 +- src/eth_provider/database/mod.rs | 2 +- src/eth_provider/database/types/transaction.rs | 2 +- src/eth_provider/provider.rs | 4 ++-- src/eth_rpc/middleware/metrics.rs | 4 ++-- src/models/transaction.rs | 2 +- src/test_utils/evm_contract.rs | 2 +- src/test_utils/katana/genesis.rs | 4 ++-- src/test_utils/mongo/mod.rs | 14 +++++++------- src/test_utils/rpc/mod.rs | 2 +- 10 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 720ebe9c4..a60fe0be0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -59,6 +59,7 @@ unused_peekable = "warn" unused_rounding = "warn" useless_let_if_seq = "warn" use_self = "warn" +missing_const_for_fn = "warn" # These are nursery lints which have findings. Allow them for now. Some are not # quite mature enough for use in our codebase and some we don't really want. @@ -71,7 +72,6 @@ empty_line_after_doc_comments = "allow" fallible_impl_from = "allow" future_not_send = "allow" iter_on_single_items = "allow" -missing_const_for_fn = "allow" needless_collect = "allow" non_send_fields_in_send_ty = "allow" option_if_let_else = "allow" diff --git a/src/eth_provider/database/mod.rs b/src/eth_provider/database/mod.rs index 92ba07de4..3639a2feb 100644 --- a/src/eth_provider/database/mod.rs +++ b/src/eth_provider/database/mod.rs @@ -28,7 +28,7 @@ impl Database { } /// Get a reference to the inner MongoDatabase - pub fn inner(&self) -> &MongoDatabase { + pub const fn inner(&self) -> &MongoDatabase { &self.0 } diff --git a/src/eth_provider/database/types/transaction.rs b/src/eth_provider/database/types/transaction.rs index f9b0421dc..f3c2ac923 100644 --- a/src/eth_provider/database/types/transaction.rs +++ b/src/eth_provider/database/types/transaction.rs @@ -72,7 +72,7 @@ pub struct StoredPendingTransaction { } impl StoredPendingTransaction { - pub fn new(tx: Transaction, retries: u64) -> Self { + pub const fn new(tx: Transaction, retries: u64) -> Self { Self { tx, retries } } } diff --git a/src/eth_provider/provider.rs b/src/eth_provider/provider.rs index a223c7702..3c60e4c65 100644 --- a/src/eth_provider/provider.rs +++ b/src/eth_provider/provider.rs @@ -146,7 +146,7 @@ where SP: starknet::providers::Provider, { /// Returns a reference to the database. - pub fn database(&self) -> &Database { + pub const fn database(&self) -> &Database { &self.database } } @@ -653,7 +653,7 @@ where } #[cfg(feature = "testing")] - pub fn starknet_provider(&self) -> &SP { + pub const fn starknet_provider(&self) -> &SP { &self.starknet_provider } diff --git a/src/eth_rpc/middleware/metrics.rs b/src/eth_rpc/middleware/metrics.rs index cbf2eac47..d1e90cf59 100644 --- a/src/eth_rpc/middleware/metrics.rs +++ b/src/eth_rpc/middleware/metrics.rs @@ -106,7 +106,7 @@ pub struct MetricsLayer { impl MetricsLayer { /// Create a new [`MetricsLayer`]. - pub fn new(metrics: RpcMetrics, transport_label: &'static str) -> Self { + pub const fn new(metrics: RpcMetrics, transport_label: &'static str) -> Self { Self { inner: metrics, transport_label } } } @@ -129,7 +129,7 @@ pub struct Metrics { impl Metrics { /// Create a new metrics middleware. - pub fn new(service: S, metrics: RpcMetrics, transport_label: &'static str) -> Self { + pub const fn new(service: S, metrics: RpcMetrics, transport_label: &'static str) -> Self { Self { service, metrics, transport_label } } } diff --git a/src/models/transaction.rs b/src/models/transaction.rs index 9de35b2e2..d764b5615 100644 --- a/src/models/transaction.rs +++ b/src/models/transaction.rs @@ -55,7 +55,7 @@ mod tests { self } - fn with_fee_market(mut self) -> Self { + const fn with_fee_market(mut self) -> Self { self.tx.max_fee_per_gas = Some(30); self.tx.max_priority_fee_per_gas = Some(10); self diff --git a/src/test_utils/evm_contract.rs b/src/test_utils/evm_contract.rs index d0cd544ca..a7e11dbca 100644 --- a/src/test_utils/evm_contract.rs +++ b/src/test_utils/evm_contract.rs @@ -20,7 +20,7 @@ pub enum TransactionInfo { macro_rules! impl_common_info { ($field: ident, $type: ty) => { - pub fn $field(&self) -> $type { + pub const fn $field(&self) -> $type { match self { TransactionInfo::FeeMarketInfo(info) => info.common.$field, TransactionInfo::LegacyInfo(info) => info.common.$field, diff --git a/src/test_utils/katana/genesis.rs b/src/test_utils/katana/genesis.rs index a4e696ade..68dd400f0 100644 --- a/src/test_utils/katana/genesis.rs +++ b/src/test_utils/katana/genesis.rs @@ -344,11 +344,11 @@ impl KatanaGenesisBuilder { self.cache.get(key).cloned().ok_or(eyre!("Cache miss for {key} address")) } - pub fn cache(&self) -> &HashMap { + pub const fn cache(&self) -> &HashMap { &self.cache } - pub fn class_hashes(&self) -> &HashMap { + pub const fn class_hashes(&self) -> &HashMap { &self.class_hashes } } diff --git a/src/test_utils/mongo/mod.rs b/src/test_utils/mongo/mod.rs index 10250c941..b4f8b878c 100644 --- a/src/test_utils/mongo/mod.rs +++ b/src/test_utils/mongo/mod.rs @@ -80,7 +80,7 @@ pub enum StoredData { impl StoredData { /// Extracts the stored header if it exists, otherwise returns None. - pub fn extract_stored_header(&self) -> Option<&StoredHeader> { + pub const fn extract_stored_header(&self) -> Option<&StoredHeader> { match self { Self::StoredHeader(header) => Some(header), _ => None, @@ -88,7 +88,7 @@ impl StoredData { } /// Extracts the stored transaction if it exists, otherwise returns None. - pub fn extract_stored_transaction(&self) -> Option<&StoredTransaction> { + pub const fn extract_stored_transaction(&self) -> Option<&StoredTransaction> { match self { Self::StoredTransaction(transaction) => Some(transaction), _ => None, @@ -96,7 +96,7 @@ impl StoredData { } /// Extracts the stored transaction receipt if it exists, otherwise returns None. - pub fn extract_stored_transaction_receipt(&self) -> Option<&StoredTransactionReceipt> { + pub const fn extract_stored_transaction_receipt(&self) -> Option<&StoredTransactionReceipt> { match self { Self::StoredTransactionReceipt(receipt) => Some(receipt), _ => None, @@ -104,7 +104,7 @@ impl StoredData { } /// Extracts the stored log if it exists, otherwise returns None. - pub fn extract_stored_log(&self) -> Option<&StoredLog> { + pub const fn extract_stored_log(&self) -> Option<&StoredLog> { match self { Self::StoredLog(log) => Some(log), _ => None, @@ -167,7 +167,7 @@ impl MongoFuzzer { } /// Obtains an immutable reference to the documents HashMap. - pub fn documents(&self) -> &HashMap> { + pub const fn documents(&self) -> &HashMap> { &self.documents } @@ -178,7 +178,7 @@ impl MongoFuzzer { } /// Get port number - pub fn port(&self) -> u16 { + pub const fn port(&self) -> u16 { self.port } @@ -379,7 +379,7 @@ pub struct TransactionBuilder { impl TransactionBuilder { /// Specifies the type of transaction to build. - pub fn with_tx_type(mut self, tx_type: TxType) -> Self { + pub const fn with_tx_type(mut self, tx_type: TxType) -> Self { self.tx_type = Some(tx_type); self } diff --git a/src/test_utils/rpc/mod.rs b/src/test_utils/rpc/mod.rs index ba414cae0..7ffbf9a13 100644 --- a/src/test_utils/rpc/mod.rs +++ b/src/test_utils/rpc/mod.rs @@ -110,7 +110,7 @@ impl RawRpcParamsBuilder { } /// Sets the ID for the JSON-RPC request. - pub fn set_id(mut self, id: i32) -> Self { + pub const fn set_id(mut self, id: i32) -> Self { self.id = id; self }