Skip to content

Commit

Permalink
Add missing_const_for_fn clippy lint (paradigmxyz#8498)
Browse files Browse the repository at this point in the history
  • Loading branch information
tcoratger authored May 30, 2024
1 parent 9906819 commit 3d3f52b
Show file tree
Hide file tree
Showing 255 changed files with 834 additions and 804 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,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.
Expand All @@ -165,7 +166,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"
Expand Down
2 changes: 1 addition & 1 deletion bin/reth/src/commands/db/checksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub(crate) struct ChecksumViewer<'a, DB: Database> {
}

impl<DB: Database> ChecksumViewer<'_, DB> {
pub(crate) fn new(tool: &'_ DbTool<DB>) -> ChecksumViewer<'_, DB> {
pub(crate) const fn new(tool: &'_ DbTool<DB>) -> ChecksumViewer<'_, DB> {
ChecksumViewer { tool, start_key: None, end_key: None, limit: None }
}

Expand Down
2 changes: 1 addition & 1 deletion bin/reth/src/commands/db/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ enum ExtraTableElement<T: Table> {

impl<T: Table> ExtraTableElement<T> {
/// Return the key for the extra element
fn key(&self) -> &T::Key {
const fn key(&self) -> &T::Key {
match self {
Self::First { key, .. } => key,
Self::Second { key, .. } => key,
Expand Down
4 changes: 2 additions & 2 deletions bin/reth/src/commands/db/tui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ enum Entries<T: Table> {
impl<T: Table> Entries<T> {
/// Creates new empty [Entries] as [Entries::RawValues] if `raw_values == true` and as
/// [Entries::Values] if `raw == false`.
fn new_with_raw_values(raw_values: bool) -> Self {
const fn new_with_raw_values(raw_values: bool) -> Self {
if raw_values {
Self::RawValues(Vec::new())
} else {
Expand Down Expand Up @@ -85,7 +85,7 @@ impl<T: Table> Entries<T> {

/// Returns an iterator over keys of the internal [Vec]. For both [Entries::RawValues] and
/// [Entries::Values], this iterator will yield [Table::Key].
fn iter_keys(&self) -> EntriesKeyIter<'_, T> {
const fn iter_keys(&self) -> EntriesKeyIter<'_, T> {
EntriesKeyIter { entries: self, index: 0 }
}
}
Expand Down
2 changes: 1 addition & 1 deletion bin/reth/src/sigsegv_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,6 @@ fn min_sigstack_size() -> usize {

/// Not all OS support hardware where this is needed.
#[cfg(not(any(target_os = "linux", target_os = "android")))]
fn min_sigstack_size() -> usize {
const fn min_sigstack_size() -> usize {
libc::MINSIGSTKSZ
}
32 changes: 16 additions & 16 deletions crates/blockchain-tree-api/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,19 @@ pub enum CanonicalError {

impl CanonicalError {
/// Returns `true` if the error is fatal.
pub fn is_fatal(&self) -> bool {
pub const fn is_fatal(&self) -> bool {
matches!(self, Self::CanonicalCommit(_) | Self::CanonicalRevert(_))
}

/// Returns `true` if the underlying error matches
/// [BlockchainTreeError::BlockHashNotFoundInChain].
pub fn is_block_hash_not_found(&self) -> bool {
pub const fn is_block_hash_not_found(&self) -> bool {
matches!(self, Self::BlockchainTree(BlockchainTreeError::BlockHashNotFoundInChain { .. }))
}

/// Returns `Some(BlockNumber)` if the underlying error matches
/// [CanonicalError::OptimisticTargetRevert].
pub fn optimistic_revert_block_number(&self) -> Option<BlockNumber> {
pub const fn optimistic_revert_block_number(&self) -> Option<BlockNumber> {
match self {
Self::OptimisticTargetRevert(block_number) => Some(*block_number),
_ => None,
Expand Down Expand Up @@ -137,13 +137,13 @@ impl InsertBlockError {

/// Returns the error kind
#[inline]
pub fn kind(&self) -> &InsertBlockErrorKind {
pub const fn kind(&self) -> &InsertBlockErrorKind {
&self.inner.kind
}

/// Returns the block that resulted in the error
#[inline]
pub fn block(&self) -> &SealedBlock {
pub const fn block(&self) -> &SealedBlock {
&self.inner.block
}

Expand Down Expand Up @@ -198,7 +198,7 @@ impl std::error::Error for InsertBlockErrorData {
}

impl InsertBlockErrorData {
fn new(block: SealedBlock, kind: InsertBlockErrorKind) -> Self {
const fn new(block: SealedBlock, kind: InsertBlockErrorKind) -> Self {
Self { block, kind }
}

Expand Down Expand Up @@ -238,17 +238,17 @@ pub enum InsertBlockErrorKind {

impl InsertBlockErrorKind {
/// Returns true if the error is a tree error
pub fn is_tree_error(&self) -> bool {
pub const fn is_tree_error(&self) -> bool {
matches!(self, Self::Tree(_))
}

/// Returns true if the error is a consensus error
pub fn is_consensus_error(&self) -> bool {
pub const fn is_consensus_error(&self) -> bool {
matches!(self, Self::Consensus(_))
}

/// Returns true if this error is a state root error
pub fn is_state_root_error(&self) -> bool {
pub const fn is_state_root_error(&self) -> bool {
// we need to get the state root errors inside of the different variant branches
match self {
Self::Execution(err) => {
Expand Down Expand Up @@ -280,7 +280,7 @@ impl InsertBlockErrorKind {
/// Returns true if the error is caused by an invalid block
///
/// This is intended to be used to determine if the block should be marked as invalid.
pub fn is_invalid_block(&self) -> bool {
pub const fn is_invalid_block(&self) -> bool {
match self {
Self::SenderRecovery | Self::Consensus(_) => true,
// other execution errors that are considered internal errors
Expand Down Expand Up @@ -331,7 +331,7 @@ impl InsertBlockErrorKind {
}

/// Returns true if this is a block pre merge error.
pub fn is_block_pre_merge(&self) -> bool {
pub const fn is_block_pre_merge(&self) -> bool {
matches!(
self,
Self::Execution(BlockExecutionError::Validation(
Expand All @@ -341,33 +341,33 @@ impl InsertBlockErrorKind {
}

/// Returns true if the error is an execution error
pub fn is_execution_error(&self) -> bool {
pub const fn is_execution_error(&self) -> bool {
matches!(self, Self::Execution(_))
}

/// Returns true if the error is an internal error
pub fn is_internal(&self) -> bool {
pub const fn is_internal(&self) -> bool {
matches!(self, Self::Internal(_))
}

/// Returns the error if it is a tree error
pub fn as_tree_error(&self) -> Option<BlockchainTreeError> {
pub const fn as_tree_error(&self) -> Option<BlockchainTreeError> {
match self {
Self::Tree(err) => Some(*err),
_ => None,
}
}

/// Returns the error if it is a consensus error
pub fn as_consensus_error(&self) -> Option<&ConsensusError> {
pub const fn as_consensus_error(&self) -> Option<&ConsensusError> {
match self {
Self::Consensus(err) => Some(err),
_ => None,
}
}

/// Returns the error if it is an execution error
pub fn as_execution_error(&self) -> Option<&BlockExecutionError> {
pub const fn as_execution_error(&self) -> Option<&BlockExecutionError> {
match self {
Self::Execution(err) => Some(err),
_ => None,
Expand Down
6 changes: 3 additions & 3 deletions crates/blockchain-tree-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ pub enum BlockValidationKind {

impl BlockValidationKind {
/// Returns true if the state root should be validated if possible.
pub fn is_exhaustive(&self) -> bool {
pub const fn is_exhaustive(&self) -> bool {
matches!(self, Self::Exhaustive)
}
}
Expand Down Expand Up @@ -177,7 +177,7 @@ pub enum CanonicalOutcome {

impl CanonicalOutcome {
/// Returns the header of the block that was made canonical.
pub fn header(&self) -> &SealedHeader {
pub const fn header(&self) -> &SealedHeader {
match self {
Self::AlreadyCanonical { header, .. } => header,
Self::Committed { head } => head,
Expand All @@ -193,7 +193,7 @@ impl CanonicalOutcome {
}

/// Returns true if the block was already canonical.
pub fn is_already_canonical(&self) -> bool {
pub const fn is_already_canonical(&self) -> bool {
matches!(self, Self::AlreadyCanonical { .. })
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/blockchain-tree/src/block_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl BlockBuffer {
}

/// Return reference to buffered blocks
pub fn blocks(&self) -> &HashMap<BlockHash, SealedBlockWithSenders> {
pub const fn blocks(&self) -> &HashMap<BlockHash, SealedBlockWithSenders> {
&self.blocks
}

Expand Down
8 changes: 4 additions & 4 deletions crates/blockchain-tree/src/block_indices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ impl BlockIndices {
}

/// Return fork to child indices
pub fn fork_to_child(&self) -> &HashMap<BlockHash, LinkedHashSet<BlockHash>> {
pub const fn fork_to_child(&self) -> &HashMap<BlockHash, LinkedHashSet<BlockHash>> {
&self.fork_to_child
}

/// Return block to chain id
pub fn blocks_to_chain(&self) -> &HashMap<BlockHash, BlockchainId> {
pub const fn blocks_to_chain(&self) -> &HashMap<BlockHash, BlockchainId> {
&self.blocks_to_chain
}

Expand Down Expand Up @@ -94,7 +94,7 @@ impl BlockIndices {
}

/// Last finalized block
pub fn last_finalized_block(&self) -> BlockNumber {
pub const fn last_finalized_block(&self) -> BlockNumber {
self.last_finalized_block
}

Expand Down Expand Up @@ -366,7 +366,7 @@ impl BlockIndices {

/// Canonical chain needed for execution of EVM. It should contain last 256 block hashes.
#[inline]
pub(crate) fn canonical_chain(&self) -> &CanonicalChain {
pub(crate) const fn canonical_chain(&self) -> &CanonicalChain {
&self.canonical_chain
}
}
4 changes: 2 additions & 2 deletions crates/blockchain-tree/src/blockchain_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ where

/// Expose internal indices of the BlockchainTree.
#[inline]
pub fn block_indices(&self) -> &BlockIndices {
pub const fn block_indices(&self) -> &BlockIndices {
self.state.block_indices()
}

Expand Down Expand Up @@ -1463,7 +1463,7 @@ mod tests {
}

impl TreeTester {
fn with_chain_num(mut self, chain_num: usize) -> Self {
const fn with_chain_num(mut self, chain_num: usize) -> Self {
self.chain_num = Some(chain_num);
self
}
Expand Down
2 changes: 1 addition & 1 deletion crates/blockchain-tree/src/canonical_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl CanonicalChain {
}

#[inline]
pub(crate) fn inner(&self) -> &BTreeMap<BlockNumber, BlockHash> {
pub(crate) const fn inner(&self) -> &BTreeMap<BlockNumber, BlockHash> {
&self.chain
}

Expand Down
2 changes: 1 addition & 1 deletion crates/blockchain-tree/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl DerefMut for AppendableChain {

impl AppendableChain {
/// Create a new appendable chain from a given chain.
pub fn new(chain: Chain) -> Self {
pub const fn new(chain: Chain) -> Self {
Self { chain }
}

Expand Down
8 changes: 4 additions & 4 deletions crates/blockchain-tree/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,18 @@ impl BlockchainTreeConfig {
}

/// Return the maximum reorg depth.
pub fn max_reorg_depth(&self) -> u64 {
pub const fn max_reorg_depth(&self) -> u64 {
self.max_reorg_depth
}

/// Return the maximum number of blocks in one chain.
pub fn max_blocks_in_chain(&self) -> u64 {
pub const fn max_blocks_in_chain(&self) -> u64 {
self.max_blocks_in_chain
}

/// Return number of additional canonical block hashes that we need to retain
/// in order to have enough information for EVM execution.
pub fn num_of_additional_canonical_block_hashes(&self) -> u64 {
pub const fn num_of_additional_canonical_block_hashes(&self) -> u64 {
self.num_of_additional_canonical_block_hashes
}

Expand All @@ -84,7 +84,7 @@ impl BlockchainTreeConfig {
}

/// Return max number of unconnected blocks that we are buffering
pub fn max_unconnected_blocks(&self) -> u32 {
pub const fn max_unconnected_blocks(&self) -> u32 {
self.max_unconnected_blocks
}
}
2 changes: 1 addition & 1 deletion crates/blockchain-tree/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub(crate) enum MakeCanonicalAction {
}

impl MakeCanonicalAction {
fn as_str(&self) -> &'static str {
const fn as_str(&self) -> &'static str {
match self {
Self::CloneOldBlocks => "clone old blocks",
Self::FindCanonicalHeader => "find canonical header",
Expand Down
2 changes: 1 addition & 1 deletion crates/blockchain-tree/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl TreeState {

/// Expose internal indices of the BlockchainTree.
#[inline]
pub(crate) fn block_indices(&self) -> &BlockIndices {
pub(crate) const fn block_indices(&self) -> &BlockIndices {
&self.block_indices
}

Expand Down
2 changes: 1 addition & 1 deletion crates/config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ impl Default for EtlConfig {

impl EtlConfig {
/// Creates an ETL configuration
pub fn new(dir: Option<PathBuf>, file_size: usize) -> Self {
pub const fn new(dir: Option<PathBuf>, file_size: usize) -> Self {
Self { dir, file_size }
}

Expand Down
2 changes: 1 addition & 1 deletion crates/consensus/auto-seal/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct AutoSealClient {
}

impl AutoSealClient {
pub(crate) fn new(storage: Storage) -> Self {
pub(crate) const fn new(storage: Storage) -> Self {
Self { storage }
}

Expand Down
Loading

0 comments on commit 3d3f52b

Please sign in to comment.