Skip to content

Commit

Permalink
Before tackling the 'pattern_type_mismatch' lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ntn-x2 committed Oct 17, 2024
1 parent 86e11f8 commit 55d6476
Show file tree
Hide file tree
Showing 19 changed files with 98 additions and 14 deletions.
43 changes: 43 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,46 @@
# Generic lints
[build]
rustflags = [
"-Wclippy::alloc_instead_of_core",
"-Wclippy::as_underscore",
"-Wclippy::clone_on_ref_ptr",
"-Wclippy::decimal_literal_representation",
"-Wclippy::default_numeric_fallback",
"-Wclippy::else_if_without_else",
"-Wclippy::empty_drop",
"-Wclippy::empty_structs_with_brackets",
"-Wclippy::error_impl_error",
"-Wclippy::if_then_some_else_none",
"-Wclippy::impl_trait_in_params",
"-Wclippy::let_underscore_must_use",
"-Wclippy::let_underscore_untyped",
"-Wclippy::mixed_read_write_in_expression",
"-Wclippy::negative_feature_names",
"-Wclippy::pattern_type_mismatch",
"-Wclippy::pub_without_shorthand",
"-Wclippy::redundant_type_annotations",
"-Wclippy::ref_patterns",
"-Wclippy::rest_pat_in_fully_bound_structs",
"-Wclippy::shadow_reuse",
"-Wclippy::shadow_same",
"-Wclippy::shadow_unrelated",
"-Wclippy::str_to_string",
"-Wclippy::string_slice",
"-Wclippy::string_to_string",
"-Wclippy::tests_outside_test_module",
"-Wclippy::unnecessary_self_imports",
"-Wclippy::unneeded_field_pattern",
'-Wclippy::wildcard_dependencies',
# TODO: Add after upgrading to 1.77
#"-Wclippy::empty_enum_variants_with_brackets",
# TODO: Add after upgrading to 1.80
#"-Wclippy::renamed_function_params",
# TODO: Add after upgrading to 1.81
#"-Wclippy::cfg_not_test",
# TODO: Add after upgrading to 1.83
#"-Wclippy::unused_trait_names",
]

# Deployment runtime lints
[target.'cfg(all(target_arch = "wasm32", not(test)))']
rustflags = [
Expand Down
22 changes: 14 additions & 8 deletions dip-template/pallets/pallet-postit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ pub use pallet::*;
#[allow(clippy::expect_used)]
// `unreachable` is used in the macro-generated code, and we have to ignore it.
#[allow(clippy::unreachable)]
#[allow(clippy::shadow_reuse)]
#[allow(clippy::ref_patterns)]
pub mod pallet {

use super::*;
Expand Down Expand Up @@ -120,8 +122,9 @@ pub mod pallet {
.as_slice(),
);
Posts::<T>::try_mutate(resource_id, |post| {
if let Some(post) = post {
post.comments
if let Some(ref mut existing_post) = *post {
existing_post
.comments
.try_push(comment_id)
.expect("Failed to add comment to post.");
Ok(())
Expand All @@ -131,8 +134,8 @@ pub mod pallet {
})
.or_else(|_| {
Comments::<T>::try_mutate(resource_id, |comment| {
if let Some(comment) = comment {
comment
if let Some(ref mut existing_comment) = *comment {
existing_comment
.details
.comments
.try_push(comment_id)
Expand Down Expand Up @@ -160,17 +163,20 @@ pub mod pallet {
let success_origin = T::OriginCheck::ensure_origin(origin)?;
let liker = success_origin.username().map_err(DispatchError::Other)?;
Posts::<T>::try_mutate(resource_id, |post| {
if let Some(post) = post {
post.likes.try_push(liker.clone()).expect("Failed to add like to post.");
if let Some(ref mut existing_post) = *post {
existing_post
.likes
.try_push(liker.clone())
.expect("Failed to add like to post.");
Ok(())
} else {
Err(())
}
})
.or_else(|_| {
Comments::<T>::try_mutate(resource_id, |comment| {
if let Some(comment) = comment {
comment
if let Some(ref mut existing_comment) = comment {
existing_comment
.details
.likes
.try_push(liker.clone())
Expand Down
2 changes: 2 additions & 0 deletions pallets/attestation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ pub use crate::{
#[allow(clippy::expect_used)]
// `unreachable` is used in the macro-generated code, and we have to ignore it.
#[allow(clippy::unreachable)]
#[allow(clippy::shadow_reuse)]
#[allow(clippy::ref_patterns)]
pub mod pallet {
use super::*;

Expand Down
2 changes: 2 additions & 0 deletions pallets/ctype/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ pub use crate::{default_weights::WeightInfo, pallet::*};
#[allow(clippy::expect_used)]
// `unreachable` is used in the macro-generated code, and we have to ignore it.
#[allow(clippy::unreachable)]
#[allow(clippy::shadow_reuse)]
#[allow(clippy::ref_patterns)]
pub mod pallet {
use super::*;
use frame_support::{
Expand Down
15 changes: 10 additions & 5 deletions pallets/delegation/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,9 +488,14 @@ benchmarks! {
let origin = RawOrigin::Signed(deposit_owner);
}: _(origin, hierarchy_id)

impl_benchmark_test_suite!(
Pallet,
crate::mock::runtime::ExtBuilder::default().build_with_keystore(),
crate::mock::runtime::Test
)
#[cfg(test)]
mod tests {
use super::*;

impl_benchmark_test_suite!(
Pallet,
crate::mock::runtime::ExtBuilder::default().build_with_keystore(),
crate::mock::runtime::Test
)
}
}
2 changes: 2 additions & 0 deletions pallets/delegation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ use sp_std::{marker::PhantomData, vec::Vec};
#[allow(clippy::expect_used)]
// `unreachable` is used in the macro-generated code, and we have to ignore it.
#[allow(clippy::unreachable)]
#[allow(clippy::shadow_reuse)]
#[allow(clippy::ref_patterns)]
pub mod pallet {

use super::*;
Expand Down
2 changes: 1 addition & 1 deletion pallets/delegation/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ pub(crate) mod runtime {
// the genesis block.
System::set_block_number(System::block_number() + 1);

for (ctype_hash, owner) in self.ctypes.iter() {
for (&ctype_hash, &owner) in self.ctypes.iter() {
ctype::Ctypes::<Test>::insert(
ctype_hash,
CtypeEntryOf::<Test> {
Expand Down
2 changes: 2 additions & 0 deletions pallets/did/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ use frame_system::RawOrigin;
#[allow(clippy::expect_used)]
// `unreachable` is used in the macro-generated code, and we have to ignore it.
#[allow(clippy::unreachable)]
#[allow(clippy::shadow_reuse)]
#[allow(clippy::ref_patterns)]
pub mod pallet {
use super::*;
use did_details::DidCreationDetails;
Expand Down
2 changes: 2 additions & 0 deletions pallets/pallet-asset-switch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ const LOG_TARGET: &str = "runtime::pallet-asset-switch";
#[allow(clippy::expect_used)]
// `unreachable` is used in the macro-generated code, and we have to ignore it.
#[allow(clippy::unreachable)]
#[allow(clippy::shadow_reuse)]
#[allow(clippy::ref_patterns)]
pub mod pallet {
use crate::{
switch::{NewSwitchPairInfo, SwitchPairInfo, SwitchPairInfoV4, SwitchPairStatus, UnconfirmedSwitchInfo},
Expand Down
2 changes: 2 additions & 0 deletions pallets/pallet-configuration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ pub use crate::{configuration::Configuration, default_weights::WeightInfo, palle
#[allow(clippy::expect_used)]
// `unreachable` is used in the macro-generated code, and we have to ignore it.
#[allow(clippy::unreachable)]
#[allow(clippy::shadow_reuse)]
#[allow(clippy::ref_patterns)]
pub mod pallet {
use super::*;

Expand Down
2 changes: 2 additions & 0 deletions pallets/pallet-deposit-storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ const LOG_TARGET: &str = "pallet_deposit_storage";
#[allow(clippy::expect_used)]
// `unreachable` is used in the macro-generated code, and we have to ignore it.
#[allow(clippy::unreachable)]
#[allow(clippy::shadow_reuse)]
#[allow(clippy::ref_patterns)]
pub mod pallet {
use crate::{
default_weights::WeightInfo,
Expand Down
2 changes: 2 additions & 0 deletions pallets/pallet-did-lookup/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ pub use crate::{default_weights::WeightInfo, pallet::*};
#[allow(clippy::expect_used)]
// `unreachable` is used in the macro-generated code, and we have to ignore it.
#[allow(clippy::unreachable)]
#[allow(clippy::shadow_reuse)]
#[allow(clippy::ref_patterns)]
pub mod pallet {
use crate::{
associate_account_request::AssociateAccountRequest, default_weights::WeightInfo,
Expand Down
2 changes: 2 additions & 0 deletions pallets/pallet-dip-consumer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const LOG_TARGET: &str = "dip::consumer::pallet_dip_consumer";
#[allow(clippy::expect_used)]
// `unreachable` is used in the macro-generated code, and we have to ignore it.
#[allow(clippy::unreachable)]
#[allow(clippy::shadow_reuse)]
#[allow(clippy::ref_patterns)]
pub mod pallet {
use super::*;

Expand Down
2 changes: 2 additions & 0 deletions pallets/pallet-dip-provider/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const LOG_TARGET: &str = "dip::provider::pallet_dip_provider";
#[allow(clippy::expect_used)]
// `unreachable` is used in the macro-generated code, and we have to ignore it.
#[allow(clippy::unreachable)]
#[allow(clippy::shadow_reuse)]
#[allow(clippy::ref_patterns)]
pub mod pallet {
use super::*;

Expand Down
2 changes: 2 additions & 0 deletions pallets/pallet-inflation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ pub use crate::{default_weights::WeightInfo, pallet::*};
#[allow(clippy::expect_used)]
// `unreachable` is used in the macro-generated code, and we have to ignore it.
#[allow(clippy::unreachable)]
#[allow(clippy::shadow_reuse)]
#[allow(clippy::ref_patterns)]
pub mod pallet {
use super::WeightInfo;
use frame_support::{
Expand Down
2 changes: 2 additions & 0 deletions pallets/pallet-migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ pub use crate::{default_weights::WeightInfo, pallet::*};
#[allow(clippy::expect_used)]
// `unreachable` is used in the macro-generated code, and we have to ignore it.
#[allow(clippy::unreachable)]
#[allow(clippy::shadow_reuse)]
#[allow(clippy::ref_patterns)]
pub mod pallet {
use super::*;

Expand Down
2 changes: 2 additions & 0 deletions pallets/pallet-relay-store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ const LOG_TARGET: &str = "pallet_relay_store";
#[allow(clippy::expect_used)]
// `unreachable` is used in the macro-generated code, and we have to ignore it.
#[allow(clippy::unreachable)]
#[allow(clippy::shadow_reuse)]
#[allow(clippy::ref_patterns)]
pub mod pallet {
use super::*;

Expand Down
2 changes: 2 additions & 0 deletions pallets/pallet-web3-names/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ pub use crate::{default_weights::WeightInfo, pallet::*};
#[allow(clippy::expect_used)]
// `unreachable` is used in the macro-generated code, and we have to ignore it.
#[allow(clippy::unreachable)]
#[allow(clippy::shadow_reuse)]
#[allow(clippy::ref_patterns)]
pub mod pallet {
use frame_support::{
pallet_prelude::*,
Expand Down
2 changes: 2 additions & 0 deletions pallets/public-credentials/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ pub use crate::{
#[allow(clippy::expect_used)]
// `unreachable` is used in the macro-generated code, and we have to ignore it.
#[allow(clippy::unreachable)]
#[allow(clippy::shadow_reuse)]
#[allow(clippy::ref_patterns)]
pub mod pallet {
use super::*;

Expand Down

0 comments on commit 55d6476

Please sign in to comment.