Skip to content

Commit

Permalink
chore: use workspace.lints (#676)
Browse files Browse the repository at this point in the history
* chore: use workspace.lints

* docs

* chore: clippy

* doc
  • Loading branch information
DaniPopes authored Jun 20, 2024
1 parent 4d58b39 commit 3591e8b
Show file tree
Hide file tree
Showing 42 changed files with 152 additions and 142 deletions.
21 changes: 21 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,27 @@ exclude = ["tests"]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[workspace.lints.clippy]
dbg-macro = "warn"
manual-string-new = "warn"
uninlined-format-args = "warn"
use-self = "warn"
redundant-clone = "warn"
missing-const-for-fn = "warn"

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

[workspace.lints.rustdoc]
all = "warn"

[workspace.dependencies]
# workspace crates
alloy-core = { version = "0.7.6", path = "crates/core", default-features = false }
Expand Down
10 changes: 9 additions & 1 deletion crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ exclude.workspace = true
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[lints]
workspace = true

[dependencies]
alloy-primitives = { workspace = true, default-features = false }

Expand All @@ -27,7 +30,12 @@ alloy-sol-types = { workspace = true, default-features = false, optional = true
alloy-rlp = { workspace = true, default-features = false, optional = true }

[features]
std = ["alloy-primitives/std", "alloy-json-abi?/std", "alloy-dyn-abi?/std", "alloy-sol-types?/std"]
std = [
"alloy-primitives/std",
"alloy-json-abi?/std",
"alloy-dyn-abi?/std",
"alloy-sol-types?/std",
]

dyn-abi = ["sol-types", "dep:alloy-dyn-abi"]
json-abi = ["json", "serde", "dep:alloy-json-abi"]
Expand Down
10 changes: 0 additions & 10 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,8 @@
html_logo_url = "https://raw.githubusercontent.com/alloy-rs/core/main/assets/alloy.jpg",
html_favicon_url = "https://raw.githubusercontent.com/alloy-rs/core/main/assets/favicon.ico"
)]
#![warn(
missing_copy_implementations,
missing_debug_implementations,
missing_docs,
unreachable_pub,
clippy::missing_const_for_fn,
rustdoc::all
)]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![deny(unused_must_use, rust_2018_idioms)]
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(feature = "std", allow(unused_imports))]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

#[doc(inline)]
Expand Down
10 changes: 9 additions & 1 deletion crates/dyn-abi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ exclude.workspace = true
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[lints]
workspace = true

[dependencies]
alloy-json-abi.workspace = true
alloy-sol-type-parser.workspace = true
Expand Down Expand Up @@ -55,7 +58,12 @@ std = [
"serde?/std",
"serde_json?/std",
]
eip712 = ["alloy-sol-types/eip712-serde", "dep:derive_more", "dep:serde", "dep:serde_json"]
eip712 = [
"alloy-sol-types/eip712-serde",
"dep:derive_more",
"dep:serde",
"dep:serde_json",
]
arbitrary = [
"std",
"alloy-sol-types/arbitrary",
Expand Down
2 changes: 1 addition & 1 deletion crates/dyn-abi/benches/abi.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(unknown_lints, clippy::incompatible_msrv)]
#![allow(unknown_lints, clippy::incompatible_msrv, missing_docs)]

use alloy_dyn_abi::{DynSolType, DynSolValue};
use alloy_primitives::{hex, U256};
Expand Down
2 changes: 1 addition & 1 deletion crates/dyn-abi/benches/types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(unknown_lints, clippy::incompatible_msrv)]
#![allow(unknown_lints, clippy::incompatible_msrv, missing_docs)]

use alloy_dyn_abi::{DynSolType, Specifier};
use alloy_sol_type_parser::TypeSpecifier;
Expand Down
2 changes: 1 addition & 1 deletion crates/dyn-abi/src/dynamic/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl From<Vec<DynSolType>> for DynSolReturns {
}

impl From<DynSolReturns> for Vec<DynSolType> {
fn from(returns: DynSolReturns) -> Vec<DynSolType> {
fn from(returns: DynSolReturns) -> Self {
returns.0
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/dyn-abi/src/dynamic/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl<'a> DynToken<'a> {

/// Fallible cast into a fixed sequence.
#[inline]
pub fn as_fixed_seq(&self) -> Option<(&[DynToken<'a>], usize)> {
pub fn as_fixed_seq(&self) -> Option<(&[Self], usize)> {
match self {
Self::FixedSeq(tokens, size) => Some((tokens, *size)),
_ => None,
Expand All @@ -102,7 +102,7 @@ impl<'a> DynToken<'a> {

/// Fallible cast into a dynamic sequence.
#[inline]
pub fn as_dynamic_seq(&self) -> Option<&[DynToken<'a>]> {
pub fn as_dynamic_seq(&self) -> Option<&[Self]> {
match self {
Self::DynSeq { contents, .. } => Some(contents),
_ => None,
Expand All @@ -111,7 +111,7 @@ impl<'a> DynToken<'a> {

/// Fallible cast into a sequence, dynamic or fixed-size
#[inline]
pub fn as_token_seq(&self) -> Option<&[DynToken<'a>]> {
pub fn as_token_seq(&self) -> Option<&[Self]> {
match self {
Self::FixedSeq(contents, _) | Self::DynSeq { contents, .. } => Some(contents),
_ => None,
Expand Down
44 changes: 21 additions & 23 deletions crates/dyn-abi/src/dynamic/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,15 @@ impl DynSolType {
/// depth of 0, while all other types have a nesting depth of at least 1.
pub fn nesting_depth(&self) -> usize {
match self {
DynSolType::Bool
| DynSolType::Int(_)
| DynSolType::Uint(_)
| DynSolType::FixedBytes(_)
| DynSolType::Address
| DynSolType::Function
| DynSolType::Bytes
| DynSolType::String => 0,
DynSolType::Array(contents) | DynSolType::FixedArray(contents, _) => {
1 + contents.nesting_depth()
}
Self::Bool
| Self::Int(_)
| Self::Uint(_)
| Self::FixedBytes(_)
| Self::Address
| Self::Function
| Self::Bytes
| Self::String => 0,
Self::Array(contents) | Self::FixedArray(contents, _) => 1 + contents.nesting_depth(),
as_tuple!(Self tuple) => 1 + tuple.iter().map(Self::nesting_depth).max().unwrap_or(0),
}
}
Expand Down Expand Up @@ -565,21 +563,21 @@ impl DynSolType {
pub fn minimum_words(&self) -> usize {
match self {
// word types are always 1
DynSolType::Bool |
DynSolType::Int(_) |
DynSolType::Uint(_) |
DynSolType::FixedBytes(_) |
DynSolType::Address |
DynSolType::Function |
Self::Bool |
Self::Int(_) |
Self::Uint(_) |
Self::FixedBytes(_) |
Self::Address |
Self::Function |
// packed/dynamic seq types may be empty
DynSolType::Bytes |
DynSolType::String |
DynSolType::Array(_) => 1,
Self::Bytes |
Self::String |
Self::Array(_) => 1,
// fixed-seq types are the sum of their components
DynSolType::FixedArray(v, size) => size * v.minimum_words(),
DynSolType::Tuple(tuple) => tuple.iter().map(|ty| ty.minimum_words()).sum(),
Self::FixedArray(v, size) => size * v.minimum_words(),
Self::Tuple(tuple) => tuple.iter().map(|ty| ty.minimum_words()).sum(),
#[cfg(feature = "eip712")]
DynSolType::CustomStruct { tuple, ..} => tuple.iter().map(|ty| ty.minimum_words()).sum(),
Self::CustomStruct { tuple, ..} => tuple.iter().map(|ty| ty.minimum_words()).sum(),
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/dyn-abi/src/ext/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use alloy_json_abi::{Constructor, Error, Function, Param};
use alloy_primitives::Selector;
use alloy_sol_types::abi::Decoder;

#[allow(unknown_lints, unnameable_types)]
mod sealed {
pub trait Sealed {}
impl Sealed for super::Constructor {}
Expand Down
1 change: 1 addition & 0 deletions crates/dyn-abi/src/ext/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use alloc::vec::Vec;
use alloy_json_abi::Error;
use alloy_primitives::{keccak256, Selector};

#[allow(unknown_lints, unnameable_types)]
mod sealed {
pub trait Sealed {}
impl Sealed for alloy_json_abi::Error {}
Expand Down
1 change: 1 addition & 0 deletions crates/dyn-abi/src/ext/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use alloc::vec::Vec;
use alloy_json_abi::Event;
use alloy_primitives::{LogData, B256};

#[allow(unknown_lints, unnameable_types)]
mod sealed {
pub trait Sealed {}
impl Sealed for alloy_json_abi::Event {}
Expand Down
10 changes: 0 additions & 10 deletions crates/dyn-abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,8 @@
html_logo_url = "https://raw.githubusercontent.com/alloy-rs/core/main/assets/alloy.jpg",
html_favicon_url = "https://raw.githubusercontent.com/alloy-rs/core/main/assets/favicon.ico"
)]
#![warn(
missing_copy_implementations,
missing_debug_implementations,
missing_docs,
unreachable_pub,
clippy::missing_const_for_fn,
rustdoc::all
)]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![deny(unused_must_use, rust_2018_idioms)]
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(feature = "std", allow(unused_imports))]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

#[macro_use]
Expand Down
10 changes: 0 additions & 10 deletions crates/json-abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,8 @@
html_logo_url = "https://raw.githubusercontent.com/alloy-rs/core/main/assets/alloy.jpg",
html_favicon_url = "https://raw.githubusercontent.com/alloy-rs/core/main/assets/favicon.ico"
)]
#![warn(
missing_copy_implementations,
missing_debug_implementations,
missing_docs,
unreachable_pub,
clippy::missing_const_for_fn,
rustdoc::all
)]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![deny(unused_must_use, rust_2018_idioms)]
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(feature = "std", allow(unused_imports))]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

#[macro_use]
Expand Down
3 changes: 3 additions & 0 deletions crates/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ exclude.workspace = true
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[lints]
workspace = true

[dependencies]
bytes.workspace = true
hex-literal.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/primitives/benches/primitives.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(unknown_lints, clippy::incompatible_msrv)]
#![allow(unknown_lints, clippy::incompatible_msrv, missing_docs)]

use alloy_primitives::{keccak256, Address, B256};
use criterion::{criterion_group, criterion_main, Criterion};
Expand Down
26 changes: 13 additions & 13 deletions crates/primitives/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ impl From<Option<Address>> for TxKind {
#[inline]
fn from(value: Option<Address>) -> Self {
match value {
None => TxKind::Create,
Some(addr) => TxKind::Call(addr),
None => Self::Create,
Some(addr) => Self::Call(addr),
}
}
}
Expand All @@ -31,29 +31,29 @@ impl From<Address> for TxKind {
/// Creates a `TxKind::Call` with the given address.
#[inline]
fn from(value: Address) -> Self {
TxKind::Call(value)
Self::Call(value)
}
}

impl TxKind {
/// Returns the address of the contract that will be called or will receive the transfer.
pub const fn to(&self) -> Option<&Address> {
match self {
TxKind::Create => None,
TxKind::Call(to) => Some(to),
Self::Create => None,
Self::Call(to) => Some(to),
}
}

/// Returns true if the transaction is a contract creation.
#[inline]
pub const fn is_create(&self) -> bool {
matches!(self, TxKind::Create)
matches!(self, Self::Create)
}

/// Returns true if the transaction is a contract call.
#[inline]
pub const fn is_call(&self) -> bool {
matches!(self, TxKind::Call(_))
matches!(self, Self::Call(_))
}

/// Calculates a heuristic for the in-memory size of this object.
Expand All @@ -67,15 +67,15 @@ impl TxKind {
impl Encodable for TxKind {
fn encode(&self, out: &mut dyn BufMut) {
match self {
TxKind::Call(to) => to.encode(out),
TxKind::Create => out.put_u8(EMPTY_STRING_CODE),
Self::Call(to) => to.encode(out),
Self::Create => out.put_u8(EMPTY_STRING_CODE),
}
}

fn length(&self) -> usize {
match self {
TxKind::Call(to) => to.length(),
TxKind::Create => 1, // EMPTY_STRING_CODE is a single byte
Self::Call(to) => to.length(),
Self::Create => 1, // EMPTY_STRING_CODE is a single byte
}
}
}
Expand All @@ -86,10 +86,10 @@ impl Decodable for TxKind {
if let Some(&first) = buf.first() {
if first == EMPTY_STRING_CODE {
buf.advance(1);
Ok(TxKind::Create)
Ok(Self::Create)
} else {
let addr = <Address as Decodable>::decode(buf)?;
Ok(TxKind::Call(addr))
Ok(Self::Call(addr))
}
} else {
Err(alloy_rlp::Error::InputTooShort)
Expand Down
10 changes: 0 additions & 10 deletions crates/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,8 @@
html_logo_url = "https://raw.githubusercontent.com/alloy-rs/core/main/assets/alloy.jpg",
html_favicon_url = "https://raw.githubusercontent.com/alloy-rs/core/main/assets/favicon.ico"
)]
#![warn(
missing_copy_implementations,
missing_debug_implementations,
missing_docs,
unreachable_pub,
clippy::missing_const_for_fn,
rustdoc::all
)]
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
#![deny(unused_must_use, rust_2018_idioms)]
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(feature = "std", allow(unused_imports))]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
// TODO: remove when https://github.com/proptest-rs/proptest/pull/427 is merged
#![allow(unknown_lints, non_local_definitions)]
Expand Down
2 changes: 1 addition & 1 deletion crates/primitives/src/log_serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl<T: Serialize> Serialize for Log<T> {
where
S: Serializer,
{
let Log { address, data } = self;
let Self { address, data } = self;
if serializer.is_human_readable() {
let replace = LogFlattenSerializer { address, data };
replace.serialize(serializer)
Expand Down
2 changes: 2 additions & 0 deletions crates/primitives/src/signature/sig.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(unknown_lints, unnameable_types)]

use crate::{
hex,
signature::{Parity, SignatureError},
Expand Down
Loading

0 comments on commit 3591e8b

Please sign in to comment.