Skip to content

Commit

Permalink
fix(axon-tools): cargo clippy --all-features errors (#1614)
Browse files Browse the repository at this point in the history
* fix(axon-tools): cargo clippy --all-features

* refactor workflow
  • Loading branch information
Eason Gao authored Dec 3, 2023
1 parent e6eee4a commit c92fbf3
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 21 deletions.
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,16 @@ check-fmt:
fmt:
cargo +nightly fmt ${VERBOSE} --all

clippy:
clippy: axon-clippy axon-tools-clippy

axon-clippy:
${CARGO} clippy ${VERBOSE} --all --all-targets --all-features -- \
-D warnings -D clippy::clone_on_ref_ptr -D clippy::enum_glob_use

axon-tools-clippy:
${CARGO} clippy ${VERBOSE} --manifest-path=devtools/axon-tools/Cargo.toml --all-features -- \
-D warnings -D clippy::clone_on_ref_ptr -D clippy::enum_glob_use

sort:
cargo sort -gw

Expand Down
3 changes: 2 additions & 1 deletion devtools/axon-tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ hash = ["tiny-keccak"]
hex = ["faster-hex"]
impl-rlp = ["rlp", "rlp-derive", "ethereum-types/rlp"]
impl-serde = ["serde", "ethereum-types/serialize"]
precompile = ["ethers-contract", "ethers-core"]
precompile = ["ckb-types", "ethers-contract", "ethers-core", "std"]
std = ["cita_trie", "hex", "log", "derive_more", "serde_json"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down Expand Up @@ -98,6 +98,7 @@ features = ["derive"]
[dependencies.serde_json]
version = "1.0"
default_features = false
features = ["alloc"]
optional = true

[dependencies.tiny-keccak]
Expand Down
4 changes: 4 additions & 0 deletions devtools/axon-tools/src/hex.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
use alloc::string::String;
use alloc::vec;
use alloc::vec::Vec;

use crate::Error;

pub fn hex_encode<T: AsRef<[u8]>>(src: T) -> String {
Expand Down
1 change: 1 addition & 0 deletions devtools/axon-tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub mod hex;
pub mod precompile;
#[cfg(feature = "proof")]
mod proof;
#[cfg(feature = "impl-rlp")]
mod rlp_codec;
pub mod types;

Expand Down
8 changes: 2 additions & 6 deletions devtools/axon-tools/src/rlp_codec.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
#[cfg(feature = "impl-rlp")]
use crate::types::BlockVersion;
#[cfg(feature = "proof")]
use crate::types::{Proposal, Vote};
#[cfg(feature = "impl-rlp")]
use rlp::{Decodable, DecoderError, Encodable, Rlp, RlpStream};

#[cfg(feature = "impl-rlp")]
impl Encodable for BlockVersion {
fn rlp_append(&self, s: &mut RlpStream) {
let ver: u8 = (*self).into();
s.begin_list(1).append(&ver);
}
}

#[cfg(feature = "impl-rlp")]
impl Decodable for BlockVersion {
fn decode(r: &Rlp) -> Result<Self, DecoderError> {
let ver: u8 = r.val_at(0)?;
Expand All @@ -22,7 +18,7 @@ impl Decodable for BlockVersion {
}
}

#[cfg(feature = "impl-rlp")]
#[cfg(feature = "proof")]
impl Encodable for Vote {
fn rlp_append(&self, s: &mut RlpStream) {
let vote_type: u8 = self.vote_type;
Expand All @@ -34,7 +30,7 @@ impl Encodable for Vote {
}
}

#[cfg(feature = "impl-rlp")]
#[cfg(feature = "proof")]
impl Encodable for Proposal {
fn rlp_append(&self, s: &mut RlpStream) {
s.begin_list(13)
Expand Down
26 changes: 13 additions & 13 deletions devtools/axon-tools/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// are recommended to ensure the definitions in this file align with those in
// the 'axon-protocol' package.
use crate::error::TypesError;
#[cfg(any(feature = "hex", feature = "impl-serde"))]
use alloc::string::String;
use alloc::vec;
use alloc::vec::Vec;
use bytes::{Bytes, BytesMut};
Expand All @@ -24,10 +26,8 @@ use crate::hex::{hex_decode, hex_encode};
use crate::Error;
#[cfg(feature = "hex")]
use core::str::FromStr;
#[cfg(feature = "hex")]
use faster_hex::withpfx_lowercase;

#[cfg(feature = "std")]
#[cfg(feature = "hex")]
const HEX_PREFIX: &str = "0x";

#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
Expand All @@ -53,7 +53,7 @@ impl Hex {

#[cfg(feature = "hex")]
pub fn as_string(&self) -> String {
HEX_PREFIX.to_string() + &hex_encode(self.0.as_ref())
String::from(HEX_PREFIX) + &hex_encode(self.0.as_ref())
}

#[cfg(feature = "hex")]
Expand Down Expand Up @@ -115,7 +115,7 @@ impl Serialize for Hex {
where
S: serde::ser::Serializer,
{
withpfx_lowercase::serialize(&self.0, serializer)
faster_hex::withpfx_lowercase::serialize(&self.0, serializer)
}
}

Expand Down Expand Up @@ -170,8 +170,8 @@ pub struct ExtraData {
#[cfg_attr(
all(feature = "impl-serde", feature = "std"),
serde(
serialize_with = "withpfx_lowercase::serialize",
deserialize_with = "withpfx_lowercase::deserialize"
serialize_with = "faster_hex::withpfx_lowercase::serialize",
deserialize_with = "faster_hex::withpfx_lowercase::deserialize"
)
)]
pub inner: Bytes,
Expand Down Expand Up @@ -314,16 +314,16 @@ pub struct Proof {
#[cfg_attr(
all(feature = "impl-serde", feature = "std"),
serde(
serialize_with = "withpfx_lowercase::serialize",
deserialize_with = "withpfx_lowercase::deserialize"
serialize_with = "faster_hex::withpfx_lowercase::serialize",
deserialize_with = "faster_hex::withpfx_lowercase::deserialize"
)
)]
pub signature: Bytes,
#[cfg_attr(
all(feature = "impl-serde", feature = "std"),
serde(
serialize_with = "withpfx_lowercase::serialize",
deserialize_with = "withpfx_lowercase::deserialize"
serialize_with = "faster_hex::withpfx_lowercase::serialize",
deserialize_with = "faster_hex::withpfx_lowercase::deserialize"
)
)]
pub bitmap: Bytes,
Expand Down Expand Up @@ -417,7 +417,7 @@ impl MetadataVersion {
all(feature = "impl-serde", feature = "std"),
derive(serde::Serialize, serde::Deserialize)
)]
#[cfg_attr(feature = "hex", derive(Debug))]
#[cfg_attr(feature = "std", derive(Debug))]
pub struct Metadata {
pub version: MetadataVersion,
#[cfg_attr(
Expand Down Expand Up @@ -532,7 +532,7 @@ impl Ord for ValidatorExtend {
}
}

#[cfg(feature = "hex")]
#[cfg(feature = "std")]
impl std::fmt::Debug for ValidatorExtend {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
let bls_pub_key = self.bls_pub_key.as_string_trim0x();
Expand Down

0 comments on commit c92fbf3

Please sign in to comment.