Skip to content

Commit

Permalink
clippy: add clippy to Cargo.toml (#27)
Browse files Browse the repository at this point in the history
* clippy: add clippy to Cargo.toml

* fix clippy

* fix clippy with latest nightly
  • Loading branch information
tcoratger authored Oct 14, 2024
1 parent 9aef28e commit 44606e8
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 30 deletions.
18 changes: 18 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@ homepage = "https://github.com/alloy-rs/rlp"
repository = "https://github.com/alloy-rs/rlp"
exclude = ["benches/", "tests/"]

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

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

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

[workspace.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
Expand Down
3 changes: 3 additions & 0 deletions crates/rlp-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ license.workspace = true
repository.workspace = true
exclude.workspace = true

[lints]
workspace = true

[lib]
proc-macro = true

Expand Down
8 changes: 2 additions & 6 deletions crates/rlp-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@
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_docs, unreachable_pub, rustdoc::all)]
#![deny(unused_must_use, unused_crate_dependencies)]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

extern crate proc_macro;

mod de;
mod en;
mod utils;

use de::*;
use en::*;
use de::{impl_decodable, impl_decodable_wrapper};
use en::{impl_encodable, impl_encodable_wrapper, impl_max_encoded_len};
use proc_macro::TokenStream;

/// Derives `Encodable` for the type which encodes the all fields as list:
Expand Down
15 changes: 8 additions & 7 deletions crates/rlp-derive/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub(crate) fn parse_struct<'a>(
}

pub(crate) fn attributes_include(attrs: &[Attribute], attr_name: &str) -> bool {
for attr in attrs.iter() {
for attr in attrs {
if attr.path().is_ident("rlp") {
if let Meta::List(meta) = &attr.meta {
let mut is_attr = false;
Expand Down Expand Up @@ -51,12 +51,13 @@ pub(crate) fn is_optional(field: &Field) -> bool {
}

pub(crate) fn field_ident(index: usize, field: &syn::Field) -> TokenStream {
if let Some(ident) = &field.ident {
quote! { #ident }
} else {
let index = syn::Index::from(index);
quote! { #index }
}
field.ident.as_ref().map_or_else(
|| {
let index = syn::Index::from(index);
quote! { #index }
},
|ident| quote! { #ident },
)
}

pub(crate) fn make_generics(generics: &Generics, trait_name: TokenStream) -> Generics {
Expand Down
3 changes: 3 additions & 0 deletions crates/rlp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ license.workspace = true
repository.workspace = true
exclude.workspace = true

[lints]
workspace = true

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
Expand Down
10 changes: 5 additions & 5 deletions crates/rlp/src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub trait Decodable: Sized {
}

/// An active RLP decoder, with a specific slice of a payload.
#[derive(Debug)]
pub struct Rlp<'a> {
payload_view: &'a [u8],
}
Expand Down Expand Up @@ -254,11 +255,10 @@ mod tests {
expected,
"input: {}{}",
hex::encode(orig),
if let Ok(expected) = &expected {
format!("; expected: {}", hex::encode(crate::encode(expected)))
} else {
String::new()
}
expected.as_ref().map_or_else(
|_| String::new(),
|expected| format!("; expected: {}", hex::encode(crate::encode(expected)))
)
);

if expected.is_ok() {
Expand Down
3 changes: 2 additions & 1 deletion crates/rlp/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl Header {
payload.advance(rlp_length);
}

return Ok(PayloadView::List(items));
Ok(PayloadView::List(items))
}

/// Encodes the header into the `out` buffer.
Expand All @@ -161,6 +161,7 @@ impl Header {
}

/// Structured representation of an RLP payload.
#[derive(Debug)]
pub enum PayloadView<'a> {
/// Payload is a byte string.
String(&'a [u8]),
Expand Down
8 changes: 0 additions & 8 deletions crates/rlp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@
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_docs,
unreachable_pub,
unused_crate_dependencies,
clippy::missing_const_for_fn,
rustdoc::all
)]
#![deny(unused_must_use, rust_2018_idioms)]
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

Expand Down
8 changes: 5 additions & 3 deletions crates/rlp/tests/derive.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Tests for the derive macros.

#![cfg(feature = "derive")]
#![allow(dead_code)]

Expand All @@ -21,7 +23,7 @@ fn simple_derive() {
}

#[test]
fn wrapper() {
const fn wrapper() {
#[derive(RlpEncodableWrapper, RlpDecodableWrapper, RlpMaxEncodedLen, PartialEq, Debug)]
struct Wrapper([u8; 8]);

Expand All @@ -30,7 +32,7 @@ fn wrapper() {
}

#[test]
fn generics() {
const fn generics() {
trait LT<'a> {}

#[derive(RlpEncodable, RlpDecodable, RlpMaxEncodedLen)]
Expand All @@ -45,7 +47,7 @@ fn generics() {
}

#[test]
fn opt() {
const fn opt() {
#[derive(RlpEncodable, RlpDecodable)]
#[rlp(trailing)]
struct Options<T>(Option<Vec<T>>);
Expand Down
3 changes: 3 additions & 0 deletions examples/enum.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//! This example demonstrates how to encode and decode an enum using
//! `alloy_rlp`.

use alloy_rlp::{encode, encode_list, Decodable, Encodable, Error, Header};
use bytes::BufMut;

Expand Down

0 comments on commit 44606e8

Please sign in to comment.