diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000000000..06328af71459c --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,14 @@ +# +# An auto defined `clippy` feature was introduced, +# but it was found to clash with user defined features, +# so was renamed to `cargo-clippy`. +# +# If you want standard clippy run: +# RUSTFLAGS= cargo clippy +[target.'cfg(feature = "cargo-clippy")'] +rustflags = [ + "-Aclippy::all", + "-Dclippy::correctness", + "-Aclippy::if-same-then-else", + "-Aclippy::clone-double-ref" +] diff --git a/.gitignore b/.gitignore index 0486a1a716e5c..7c136d6f69585 100644 --- a/.gitignore +++ b/.gitignore @@ -21,7 +21,6 @@ rls*.log .local **/hfuzz_target/ **/hfuzz_workspace/ -.cargo/ .cargo-remote.toml *.bin *.iml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index fa986923708d3..0d150d96deedc 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -311,7 +311,7 @@ cargo-deny: when: always paths: - deny.log - # FIXME: Temorarily allow to fail. + # FIXME: Temporarily allow to fail. allow_failure: true cargo-fmt: @@ -321,6 +321,13 @@ cargo-fmt: script: - cargo +nightly fmt --all -- --check +cargo-clippy: + stage: test + <<: *docker-env + <<: *test-refs + script: + - SKIP_WASM_BUILD=1 env -u RUSTFLAGS cargo +nightly clippy + cargo-check-benches: stage: test <<: *docker-env diff --git a/client/executor/src/wasm_runtime.rs b/client/executor/src/wasm_runtime.rs index b3a981d9e0821..4c768b7f9c613 100644 --- a/client/executor/src/wasm_runtime.rs +++ b/client/executor/src/wasm_runtime.rs @@ -304,7 +304,7 @@ pub fn create_wasm_runtime_with_code( // // We drop the cache_path here to silence warnings that cache_path is not used if // compiling without the `wasmtime` flag. - drop(cache_path); + let _ = cache_path; sc_executor_wasmi::create_runtime( blob, diff --git a/client/network/src/block_request_handler.rs b/client/network/src/block_request_handler.rs index 9411ca71fd009..3ea7833970d9e 100644 --- a/client/network/src/block_request_handler.rs +++ b/client/network/src/block_request_handler.rs @@ -85,13 +85,14 @@ struct SeenRequestsKey { support_multiple_justifications: bool, } +#[allow(clippy::derive_hash_xor_eq)] impl Hash for SeenRequestsKey { fn hash(&self, state: &mut H) { self.peer.hash(state); self.max_blocks.hash(state); self.direction.hash(state); self.attributes.hash(state); - + self.support_multiple_justifications.hash(state); match self.from { BlockId::Hash(h) => h.hash(state), BlockId::Number(n) => n.hash(state), diff --git a/client/network/src/state_request_handler.rs b/client/network/src/state_request_handler.rs index b4e5320ebfda8..d2e58ce955197 100644 --- a/client/network/src/state_request_handler.rs +++ b/client/network/src/state_request_handler.rs @@ -78,6 +78,7 @@ struct SeenRequestsKey { start: Vec, } +#[allow(clippy::derive_hash_xor_eq)] impl Hash for SeenRequestsKey { fn hash(&self, state: &mut H) { self.peer.hash(state); diff --git a/frame/support/src/traits/metadata.rs b/frame/support/src/traits/metadata.rs index 14b7e6d7355e2..e60cf8be8a41c 100644 --- a/frame/support/src/traits/metadata.rs +++ b/frame/support/src/traits/metadata.rs @@ -78,7 +78,7 @@ pub trait GetCallMetadata { } /// The version of a crate. -#[derive(RuntimeDebug, Eq, PartialEq, Encode, Decode, Ord, Clone, Copy, Default)] +#[derive(RuntimeDebug, Eq, PartialEq, Encode, Decode, Clone, Copy, Default)] pub struct CrateVersion { /// The major version of the crate. pub major: u16, @@ -94,14 +94,17 @@ impl CrateVersion { } } -impl sp_std::cmp::PartialOrd for CrateVersion { - fn partial_cmp(&self, other: &Self) -> Option { - let res = self - .major +impl sp_std::cmp::Ord for CrateVersion { + fn cmp(&self, other: &Self) -> sp_std::cmp::Ordering { + self.major .cmp(&other.major) - .then_with(|| self.minor.cmp(&other.minor).then_with(|| self.patch.cmp(&other.patch))); + .then_with(|| self.minor.cmp(&other.minor).then_with(|| self.patch.cmp(&other.patch))) + } +} - Some(res) +impl sp_std::cmp::PartialOrd for CrateVersion { + fn partial_cmp(&self, other: &Self) -> Option { + Some(::cmp(&self, other)) } }