Skip to content

Commit 44606e8

Browse files
authored
clippy: add clippy to Cargo.toml (#27)
* clippy: add clippy to Cargo.toml * fix clippy * fix clippy with latest nightly
1 parent 9aef28e commit 44606e8

File tree

10 files changed

+49
-30
lines changed

10 files changed

+49
-30
lines changed

Cargo.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,24 @@ homepage = "https://github.com/alloy-rs/rlp"
1212
repository = "https://github.com/alloy-rs/rlp"
1313
exclude = ["benches/", "tests/"]
1414

15+
[workspace.lints.rust]
16+
missing-debug-implementations = "warn"
17+
missing-docs = "warn"
18+
unreachable-pub = "warn"
19+
unused-must-use = "deny"
20+
rust-2018-idioms = "deny"
21+
unnameable-types = "warn"
22+
23+
[workspace.lints.rustdoc]
24+
all = "warn"
25+
26+
[workspace.lints.clippy]
27+
all = { level = "warn", priority = -1 }
28+
missing-const-for-fn = "warn"
29+
use-self = "warn"
30+
option-if-let-else = "warn"
31+
redundant-clone = "warn"
32+
1533
[workspace.metadata.docs.rs]
1634
all-features = true
1735
rustdoc-args = ["--cfg", "docsrs"]

crates/rlp-derive/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ license.workspace = true
1313
repository.workspace = true
1414
exclude.workspace = true
1515

16+
[lints]
17+
workspace = true
18+
1619
[lib]
1720
proc-macro = true
1821

crates/rlp-derive/src/lib.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,14 @@
33
html_logo_url = "https://raw.githubusercontent.com/alloy-rs/core/main/assets/alloy.jpg",
44
html_favicon_url = "https://raw.githubusercontent.com/alloy-rs/core/main/assets/favicon.ico"
55
)]
6-
#![warn(missing_docs, unreachable_pub, rustdoc::all)]
7-
#![deny(unused_must_use, unused_crate_dependencies)]
86
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
97

10-
extern crate proc_macro;
11-
128
mod de;
139
mod en;
1410
mod utils;
1511

16-
use de::*;
17-
use en::*;
12+
use de::{impl_decodable, impl_decodable_wrapper};
13+
use en::{impl_encodable, impl_encodable_wrapper, impl_max_encoded_len};
1814
use proc_macro::TokenStream;
1915

2016
/// Derives `Encodable` for the type which encodes the all fields as list:

crates/rlp-derive/src/utils.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub(crate) fn parse_struct<'a>(
2222
}
2323

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

5353
pub(crate) fn field_ident(index: usize, field: &syn::Field) -> TokenStream {
54-
if let Some(ident) = &field.ident {
55-
quote! { #ident }
56-
} else {
57-
let index = syn::Index::from(index);
58-
quote! { #index }
59-
}
54+
field.ident.as_ref().map_or_else(
55+
|| {
56+
let index = syn::Index::from(index);
57+
quote! { #index }
58+
},
59+
|ident| quote! { #ident },
60+
)
6061
}
6162

6263
pub(crate) fn make_generics(generics: &Generics, trait_name: TokenStream) -> Generics {

crates/rlp/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ license.workspace = true
1313
repository.workspace = true
1414
exclude.workspace = true
1515

16+
[lints]
17+
workspace = true
18+
1619
[package.metadata.docs.rs]
1720
all-features = true
1821
rustdoc-args = ["--cfg", "docsrs"]

crates/rlp/src/decode.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub trait Decodable: Sized {
1010
}
1111

1212
/// An active RLP decoder, with a specific slice of a payload.
13+
#[derive(Debug)]
1314
pub struct Rlp<'a> {
1415
payload_view: &'a [u8],
1516
}
@@ -254,11 +255,10 @@ mod tests {
254255
expected,
255256
"input: {}{}",
256257
hex::encode(orig),
257-
if let Ok(expected) = &expected {
258-
format!("; expected: {}", hex::encode(crate::encode(expected)))
259-
} else {
260-
String::new()
261-
}
258+
expected.as_ref().map_or_else(
259+
|_| String::new(),
260+
|expected| format!("; expected: {}", hex::encode(crate::encode(expected)))
261+
)
262262
);
263263

264264
if expected.is_ok() {

crates/rlp/src/header.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl Header {
135135
payload.advance(rlp_length);
136136
}
137137

138-
return Ok(PayloadView::List(items));
138+
Ok(PayloadView::List(items))
139139
}
140140

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

163163
/// Structured representation of an RLP payload.
164+
#[derive(Debug)]
164165
pub enum PayloadView<'a> {
165166
/// Payload is a byte string.
166167
String(&'a [u8]),

crates/rlp/src/lib.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@
33
html_logo_url = "https://raw.githubusercontent.com/alloy-rs/core/main/assets/alloy.jpg",
44
html_favicon_url = "https://raw.githubusercontent.com/alloy-rs/core/main/assets/favicon.ico"
55
)]
6-
#![warn(
7-
missing_docs,
8-
unreachable_pub,
9-
unused_crate_dependencies,
10-
clippy::missing_const_for_fn,
11-
rustdoc::all
12-
)]
13-
#![deny(unused_must_use, rust_2018_idioms)]
146
#![cfg_attr(not(feature = "std"), no_std)]
157
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
168

crates/rlp/tests/derive.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Tests for the derive macros.
2+
13
#![cfg(feature = "derive")]
24
#![allow(dead_code)]
35

@@ -21,7 +23,7 @@ fn simple_derive() {
2123
}
2224

2325
#[test]
24-
fn wrapper() {
26+
const fn wrapper() {
2527
#[derive(RlpEncodableWrapper, RlpDecodableWrapper, RlpMaxEncodedLen, PartialEq, Debug)]
2628
struct Wrapper([u8; 8]);
2729

@@ -30,7 +32,7 @@ fn wrapper() {
3032
}
3133

3234
#[test]
33-
fn generics() {
35+
const fn generics() {
3436
trait LT<'a> {}
3537

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

4749
#[test]
48-
fn opt() {
50+
const fn opt() {
4951
#[derive(RlpEncodable, RlpDecodable)]
5052
#[rlp(trailing)]
5153
struct Options<T>(Option<Vec<T>>);

examples/enum.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! This example demonstrates how to encode and decode an enum using
2+
//! `alloy_rlp`.
3+
14
use alloy_rlp::{encode, encode_list, Decodable, Encodable, Error, Header};
25
use bytes::BufMut;
36

0 commit comments

Comments
 (0)