Skip to content

Commit

Permalink
chore: Add clippy settings to Cargo.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
moricho committed Dec 4, 2024
1 parent 2440a48 commit 37b8524
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 19 deletions.
18 changes: 18 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,24 @@ homepage = "https://github.com/alloy-rs/trie"
repository = "https://github.com/alloy-rs/trie"
exclude = [".github/", "deny.toml", "release.toml", "rustfmt.toml"]

[lints.rust]
missing-debug-implementations = "warn"
missing-docs = "warn"
unreachable-pub = "warn"
unused-must-use = "deny"
rust-2018-idioms = "deny"
unnameable-types = "warn"

[lints.rustdoc]
all = "warn"

[lints.clippy]
all = { level = "warn", priority = -1 }
missing-const-for-fn = "warn"
use-self = "warn"
option-if-let-else = "warn"
redundant-clone = "warn"

[dependencies]
alloy-primitives = { version = "0.8.14", default-features = false, features = [
"rlp",
Expand Down
2 changes: 2 additions & 0 deletions benches/bench.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(missing_docs)]

use alloy_trie::nodes::encode_path_leaf;
use criterion::{
criterion_group, criterion_main, measurement::WallTime, BenchmarkGroup, Criterion,
Expand Down
12 changes: 3 additions & 9 deletions src/hash_builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,9 @@ impl HashBuilder {
}

fn current_root(&self) -> B256 {
if let Some(node_ref) = self.stack.last() {
if let Some(hash) = node_ref.as_hash() {
hash
} else {
keccak256(node_ref)
}
} else {
EMPTY_ROOT_HASH
}
self.stack.last().map_or(EMPTY_ROOT_HASH, |node_ref| {
node_ref.as_hash().map_or_else(|| keccak256(node_ref), |hash| hash)
})
}

/// Given a new element, it appends it to the stack and proceeds to loop through the stack state
Expand Down
12 changes: 6 additions & 6 deletions src/proof/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl std::error::Error for ProofVerificationError {
fn source(&self) -> ::core::option::Option<&(dyn std::error::Error + 'static)> {
#[allow(deprecated)]
match self {
ProofVerificationError::Rlp { 0: transparent } => {
Self::Rlp { 0: transparent } => {
std::error::Error::source(transparent as &dyn std::error::Error)
}
_ => None,
Expand All @@ -45,22 +45,22 @@ impl std::error::Error for ProofVerificationError {
impl fmt::Display for ProofVerificationError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ProofVerificationError::RootMismatch { got, expected } => {
Self::RootMismatch { got, expected } => {
write!(f, "root mismatch. got: {got}. expected: {expected}")
}
ProofVerificationError::ValueMismatch { path, got, expected } => {
Self::ValueMismatch { path, got, expected } => {
write!(f, "value mismatch at path {path:?}. got: {got:?}. expected: {expected:?}")
}
ProofVerificationError::UnexpectedEmptyRoot => {
Self::UnexpectedEmptyRoot => {
write!(f, "unexpected empty root node")
}
ProofVerificationError::Rlp(error) => fmt::Display::fmt(error, f),
Self::Rlp(error) => fmt::Display::fmt(error, f),
}
}
}

impl From<alloy_rlp::Error> for ProofVerificationError {
fn from(source: alloy_rlp::Error) -> Self {
ProofVerificationError::Rlp(source)
Self::Rlp(source)
}
}
8 changes: 4 additions & 4 deletions src/proof/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ impl Deref for NodeDecodingResult {

fn deref(&self) -> &Self::Target {
match self {
NodeDecodingResult::Node(node) => node.as_slice(),
NodeDecodingResult::Value(value) => value,
Self::Node(node) => node.as_slice(),
Self::Value(value) => value,
}
}
}
Expand Down Expand Up @@ -332,7 +332,7 @@ mod tests {
assert_eq!(
verify_proof(
root,
target.clone(),
target,
Some(value.to_vec()),
proof.into_nodes_sorted().iter().map(|(_, node)| node)
),
Expand Down Expand Up @@ -510,7 +510,7 @@ mod tests {
},
{
buffer.clear();
TrieNode::Leaf(LeafNode::new(Nibbles::from_nibbles([0xb]), value.clone()))
TrieNode::Leaf(LeafNode::new(Nibbles::from_nibbles([0xb]), value))
.rlp(&mut buffer)
},
],
Expand Down

0 comments on commit 37b8524

Please sign in to comment.