Fix Clippy (#2522)

* Import Clippy config from Polkadot

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Auto clippy fix

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* No tabs in comments

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Prefer matches

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Dont drop references

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Trivial

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Refactor

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* fmt

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* add clippy to ci

* Clippy reborrow

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update client/pov-recovery/src/lib.rs

Co-authored-by: Bastian Köcher <git@kchr.de>

* Update client/pov-recovery/src/lib.rs

Co-authored-by: Bastian Köcher <git@kchr.de>

* Partially revert 'Prefer matches'

Using matches! instead of match does give less compiler
checks as per review from @chevdor.

Partially reverts 8c0609677f3ea040f77fffd5be6facf7c3fec95c

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>

* Update .cargo/config.toml

Co-authored-by: Chevdor <chevdor@users.noreply.github.com>

* Revert revert 💩

Should be fine to use matches! macro since it is an explicit whitelist,
not wildcard matching.

---------

Signed-off-by: Oliver Tale-Yazdi <oliver.tale-yazdi@parity.io>
Co-authored-by: alvicsam <alvicsam@gmail.com>
Co-authored-by: Bastian Köcher <git@kchr.de>
Co-authored-by: Chevdor <chevdor@users.noreply.github.com>
Co-authored-by: parity-processbot <>
This commit is contained in:
Oliver Tale-Yazdi
2023-05-06 08:01:03 +02:00
committed by GitHub
parent b72ae577a0
commit 299d25ba4b
92 changed files with 910 additions and 967 deletions
+18 -23
View File
@@ -473,10 +473,7 @@ pub mod pallet {
check_version: bool,
) -> DispatchResult {
ensure_root(origin)?;
AuthorizedUpgrade::<T>::put(CodeUpgradeAuthorization {
code_hash: code_hash.clone(),
check_version,
});
AuthorizedUpgrade::<T>::put(CodeUpgradeAuthorization { code_hash, check_version });
Self::deposit_event(Event::UpgradeAuthorized { code_hash });
Ok(())
@@ -753,7 +750,7 @@ impl<T: Config> Pallet<T> {
let authorization = AuthorizedUpgrade::<T>::get().ok_or(Error::<T>::NothingAuthorized)?;
// ensure that the actual hash matches the authorized hash
let actual_hash = T::Hashing::hash(&code[..]);
let actual_hash = T::Hashing::hash(code);
ensure!(actual_hash == authorization.code_hash, Error::<T>::Unauthorized);
// check versions if required as part of the authorization
@@ -941,10 +938,10 @@ impl<T: Config> Pallet<T> {
// `running_mqc_heads`. Otherwise, in a block where no messages were sent in a channel
// it won't get into next block's `last_mqc_heads` and thus will be all zeros, which
// would corrupt the message queue chain.
for &(ref sender, ref channel) in ingress_channels {
for (sender, channel) in ingress_channels {
let cur_head = running_mqc_heads
.entry(sender)
.or_insert_with(|| last_mqc_heads.get(&sender).cloned().unwrap_or_default())
.or_insert_with(|| last_mqc_heads.get(sender).cloned().unwrap_or_default())
.head();
let target_head = channel.mqc_head.unwrap_or_default();
@@ -1090,22 +1087,20 @@ impl<T: Config> Pallet<T> {
// may change so that the message is no longer valid.
//
// However, changing this setting is expected to be rare.
match Self::host_configuration() {
Some(cfg) =>
if message.len() > cfg.max_upward_message_size as usize {
return Err(MessageSendError::TooBig)
},
None => {
// This storage field should carry over from the previous block. So if it's None
// then it must be that this is an edge-case where a message is attempted to be
// sent at the first block.
//
// Let's pass this message through. I think it's not unreasonable to expect that
// the message is not huge and it comes through, but if it doesn't it can be
// returned back to the sender.
//
// Thus fall through here.
},
if let Some(cfg) = Self::host_configuration() {
if message.len() > cfg.max_upward_message_size as usize {
return Err(MessageSendError::TooBig)
}
} else {
// This storage field should carry over from the previous block. So if it's None
// then it must be that this is an edge-case where a message is attempted to be
// sent at the first block.
//
// Let's pass this message through. I think it's not unreasonable to expect that
// the message is not huge and it comes through, but if it doesn't it can be
// returned back to the sender.
//
// Thus fall through here.
};
<PendingUpwardMessages<T>>::append(message.clone());
+8 -11
View File
@@ -304,7 +304,7 @@ impl BlockTests {
// begin initialization
System::reset_events();
System::initialize(&n, &Default::default(), &Default::default());
System::initialize(n, &Default::default(), &Default::default());
// now mess with the storage the way validate_block does
let mut sproof_builder = RelayStateSproofBuilder::default();
@@ -357,10 +357,8 @@ impl BlockTests {
ParachainSystem::on_finalize(*n);
// did block execution set new validation code?
if NewValidationCode::<Test>::exists() {
if self.pending_upgrade.is_some() {
panic!("attempted to set validation code while upgrade was pending");
}
if NewValidationCode::<Test>::exists() && self.pending_upgrade.is_some() {
panic!("attempted to set validation code while upgrade was pending");
}
// clean up
@@ -404,7 +402,7 @@ fn events() {
let events = System::events();
assert_eq!(
events[0].event,
RuntimeEvent::ParachainSystem(crate::Event::ValidationFunctionStored.into())
RuntimeEvent::ParachainSystem(crate::Event::ValidationFunctionStored)
);
},
)
@@ -415,10 +413,9 @@ fn events() {
let events = System::events();
assert_eq!(
events[0].event,
RuntimeEvent::ParachainSystem(
crate::Event::ValidationFunctionApplied { relay_chain_block_num: 1234 }
.into()
)
RuntimeEvent::ParachainSystem(crate::Event::ValidationFunctionApplied {
relay_chain_block_num: 1234
})
);
},
);
@@ -491,7 +488,7 @@ fn aborted_upgrade() {
let events = System::events();
assert_eq!(
events[0].event,
RuntimeEvent::ParachainSystem(crate::Event::ValidationFunctionDiscarded.into())
RuntimeEvent::ParachainSystem(crate::Event::ValidationFunctionDiscarded)
);
},
);
@@ -41,7 +41,7 @@ fn call_validate_block_encoded_header(
relay_parent_number: 1,
relay_parent_storage_root,
},
&WASM_BINARY.expect("You need to build the WASM binaries to run the tests!"),
WASM_BINARY.expect("You need to build the WASM binaries to run the tests!"),
)
.map(|v| v.head_data.0)
}
@@ -191,7 +191,7 @@ fn validate_block_invalid_parent_hash() {
.unwrap_err();
} else {
let output = Command::new(env::current_exe().unwrap())
.args(&["validate_block_invalid_parent_hash", "--", "--nocapture"])
.args(["validate_block_invalid_parent_hash", "--", "--nocapture"])
.env("RUN_TEST", "1")
.output()
.expect("Runs the test");
@@ -213,7 +213,7 @@ fn validate_block_fails_on_invalid_validation_data() {
call_validate_block(parent_head, block, Hash::random()).unwrap_err();
} else {
let output = Command::new(env::current_exe().unwrap())
.args(&["validate_block_fails_on_invalid_validation_data", "--", "--nocapture"])
.args(["validate_block_fails_on_invalid_validation_data", "--", "--nocapture"])
.env("RUN_TEST", "1")
.output()
.expect("Runs the test");
@@ -242,7 +242,7 @@ fn check_inherent_fails_on_validate_block_as_expected() {
.unwrap_err();
} else {
let output = Command::new(env::current_exe().unwrap())
.args(&["check_inherent_fails_on_validate_block_as_expected", "--", "--nocapture"])
.args(["check_inherent_fails_on_validate_block_as_expected", "--", "--nocapture"])
.env("RUN_TEST", "1")
.output()
.expect("Runs the test");
@@ -276,7 +276,7 @@ fn check_inherents_are_unsigned_and_before_all_other_extrinsics() {
.unwrap_err();
} else {
let output = Command::new(env::current_exe().unwrap())
.args(&[
.args([
"check_inherents_are_unsigned_and_before_all_other_extrinsics",
"--",
"--nocapture",