Skip to content

Commit a7d80af

Browse files
authored
Stricter Linting with Rust 1.81+ and Clippy (#2346)
# Goal The goal of this PR is to update and enable a bunch of Clippy lints. Closes #1855 # Discussion - Most of these things are normal clippy fixes - Highlighted the ones that are strange - Added `make lint-fix` that runs clippy fix # Checklist - [x] Spec version incremented?
1 parent 0880a74 commit a7d80af

File tree

122 files changed

+629
-816
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

122 files changed

+629
-816
lines changed

.maintain/frame-weight-template.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ mod tests {
134134
frame_system::limits::BlockWeights::builder()
135135
.base_block(Weight::zero())
136136
.for_class(DispatchClass::all(), |weights| {
137-
weights.base_extrinsic = ExtrinsicBaseWeight::get().into();
137+
weights.base_extrinsic = ExtrinsicBaseWeight::get();
138138
})
139139
.for_class(DispatchClass::non_mandatory(), |weights| {
140140
weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);
@@ -159,4 +159,4 @@ mod tests {
159159
}
160160
{{/if}}
161161
{{/each}}
162-
}
162+
}

.maintain/runtime-weight-template.hbs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,14 @@ mod tests {
7373
use crate::constants::{MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO};
7474
use crate::weights::extrinsic_weights::ExtrinsicBaseWeight;
7575

76+
#[allow(dead_code)]
7677
struct BlockWeights;
7778
impl Get<frame_system::limits::BlockWeights> for BlockWeights {
7879
fn get() -> frame_system::limits::BlockWeights {
7980
frame_system::limits::BlockWeights::builder()
8081
.base_block(Weight::zero())
8182
.for_class(DispatchClass::all(), |weights| {
82-
weights.base_extrinsic = ExtrinsicBaseWeight::get().into();
83+
weights.base_extrinsic = ExtrinsicBaseWeight::get();
8384
})
8485
.for_class(DispatchClass::non_mandatory(), |weights| {
8586
weights.max_total = Some(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT);
@@ -104,4 +105,4 @@ mod tests {
104105
}
105106
{{/if}}
106107
{{/each}}
107-
}
108+
}

Cargo.toml

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -172,42 +172,6 @@ sp-debug-derive = { git = "https://github.com/paritytech/polkadot-sdk", branch =
172172
nonstandard-style = "deny"
173173

174174
[workspace.lints.clippy]
175-
# These should all be removed and lints fixed/ignored in the next PR
176-
collapsible_else_if = "allow"
177-
collapsible_if = "allow"
178-
single_component_path_imports = "allow"
179-
doc_lazy_continuation = "allow"
180-
manual_unwrap_or_default = "allow"
181-
duplicated_attributes = "allow"
182-
expect_used = "allow"
183-
into_iter_on_ref = "allow"
184-
legacy_numeric_constants = "allow"
185-
unwrap_or_default = "allow"
186-
single_match = "allow"
187-
manual_range_contains = "allow"
188-
iter_cloned_collect = "allow"
189-
enum_variant_names = "allow"
190-
let_and_return = "allow"
191-
let_unit_value = "allow"
192-
match_ref_pats = "allow"
193-
multiple_bound_locations = "allow"
194-
needless_borrow = "allow"
195-
needless_borrows_for_generic_args = "allow"
196-
needless_return = "allow"
197-
ptr_arg = "allow"
198-
tabs_in_doc_comments = "allow"
199-
empty_line_after_doc_comments = "allow"
200-
redundant_closure = "allow"
201-
redundant_static_lifetimes = "allow"
202-
unconditional_recursion = "allow"
203-
unnecessary_cast = "allow"
204-
unwrap_used = "allow"
205-
useless_conversion = "allow"
206-
useless_vec = "allow"
207-
while_let_on_iterator = "allow"
208-
match_like_matches_macro = "allow"
209-
nonminimal_bool = "allow"
210-
non_minimal_cfg = "allow"
211175
# We just deny everything so that we can then build up from there
212176
correctness = { level = "deny", priority = -1 }
213177
style = { level = "deny", priority = -1 }
@@ -227,6 +191,7 @@ get_first = "allow"
227191
len_zero = "allow"
228192
large_enum_variant = "allow"
229193
empty_line_after_outer_attr = "allow"
194+
enum_variant_names = "allow"
230195

231196
[profile.release]
232197
panic = "unwind"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Frequency is a [Polkadot](https://www.parity.io/technologies/polkadot) parachain
5959

6060
## Hardware
6161

62-
Benchmarks are run on an AWS `c6i.4xlarge` and recommend collators have generally the same [reference hardware specified by Parity for Validators](https://wiki.polkadot.network/docs/maintain-guides-how-to-validate-polkadot#reference-hardware).
62+
Benchmarks are run on an AWS `m6id.2xlarge` and recommend collators have generally the same [reference hardware specified by Parity for Validators](https://docs.polkadot.com/infrastructure/running-a-validator/requirements/#minimum-hardware-requirements).
6363

6464
Non-Collator nodes may have less power, but low memory configurations may lead to out of memory errors.
6565

common/helpers/src/avro.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,13 @@ pub fn get_schema_data_map<'a>(
190190
/// let schema_fingerprint = avro::fingerprint_raw_schema(raw_schema);
191191
/// assert!(schema_fingerprint.is_ok());
192192
/// ```
193-
pub fn validate_raw_avro_schema(json_schema: &Vec<u8>) -> Result<(), AvroError> {
194-
match String::from_utf8(json_schema.clone()) {
193+
pub fn validate_raw_avro_schema(json_schema: &[u8]) -> Result<(), AvroError> {
194+
match String::from_utf8(json_schema.to_owned()) {
195195
Err(_e) => Err(AvroError::InvalidSchema("Invalid schema".to_string())),
196196
Ok(avro_schema) => {
197197
let schema_fingerprint = fingerprint_raw_schema(&avro_schema);
198198
if schema_fingerprint.is_err() {
199-
return Err(AvroError::InvalidSchema("Invalid schema".to_string()))
199+
return Err(AvroError::InvalidSchema("Invalid schema".to_string()));
200200
}
201201
Ok(())
202202
},

common/helpers/src/avro_tests.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,7 @@ fn test_bad_records() {
397397
let translated_schema = translate_schema.unwrap();
398398
let writer = avro::get_schema_data_writer(&translated_schema);
399399
assert_eq!(writer.schema(), &translated_schema);
400-
let mut serialized_result = Vec::new();
401-
// populated serialized_result
402-
serialized_result.push(0x0);
400+
let serialized_result = vec![0u8];
403401
let reader_res = avro::get_schema_data_map(&serialized_result, &translated_schema);
404402
assert!(reader_res.is_err());
405403
}

common/primitives/src/messages.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ mod tests {
187187
"{\"provider_msa_id\":1,\"index\":1,\"block_number\":1,\"msa_id\":1}";
188188

189189
let deserialized_result: MessageResponse =
190-
serde_json::from_str(&serialized_msg_without_payload).unwrap();
190+
serde_json::from_str(serialized_msg_without_payload).unwrap();
191191
assert_eq!(deserialized_result, expected_msg);
192192
}
193193

@@ -257,9 +257,9 @@ mod tests {
257257
&request,
258258
);
259259
// NOT FULL
260-
assert_eq!(false, is_full);
260+
assert!(!is_full);
261261
// NOTHING MORE
262-
assert_eq!(false, resp.has_next);
262+
assert!(!resp.has_next);
263263
// None
264264
assert_eq!(None, resp.next_block);
265265
assert_eq!(None, resp.next_index);
@@ -294,8 +294,8 @@ mod tests {
294294
list_size,
295295
&request,
296296
);
297-
assert_eq!(true, is_full);
298-
assert_eq!(true, resp.has_next);
297+
assert!(is_full);
298+
assert!(resp.has_next);
299299
// SAME block
300300
assert_eq!(Some(1), resp.next_block);
301301
// NEXT index
@@ -331,8 +331,8 @@ mod tests {
331331
list_size,
332332
&request,
333333
);
334-
assert_eq!(true, is_full);
335-
assert_eq!(true, resp.has_next);
334+
assert!(is_full);
335+
assert!(resp.has_next);
336336
// NEXT block
337337
assert_eq!(Some(current_block + 1), resp.next_block);
338338
// ZERO index

common/primitives/src/offchain.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use sp_externalities::ExternalitiesExt;
66
use sp_runtime::offchain::storage::{StorageRetrievalError, StorageValueRef};
77
use sp_runtime_interface::runtime_interface;
88
extern crate alloc;
9-
use alloc::{vec, vec::Vec};
9+
use alloc::vec::Vec;
1010
use core::fmt::Debug;
1111

1212
#[cfg(feature = "std")]
@@ -35,12 +35,12 @@ pub const MSA_ACCOUNT_STORAGE_NAME_PREFIX: &[u8; 16] = b"Msa::ofw::keys::";
3535
/// msa account lock name
3636
pub fn get_msa_account_lock_name(msa_id: MessageSourceId) -> Vec<u8> {
3737
let mut buff = [0u8; 30];
38-
vec![MSA_ACCOUNT_LOCK_NAME_PREFIX, msa_id.numtoa(10, &mut buff)].concat()
38+
[MSA_ACCOUNT_LOCK_NAME_PREFIX, msa_id.numtoa(10, &mut buff)].concat()
3939
}
4040
/// msa account storage key name
4141
pub fn get_msa_account_storage_key_name(msa_id: MessageSourceId) -> Vec<u8> {
4242
let mut buff = [0u8; 30];
43-
vec![MSA_ACCOUNT_STORAGE_NAME_PREFIX, msa_id.numtoa(10, &mut buff)].concat()
43+
[MSA_ACCOUNT_STORAGE_NAME_PREFIX, msa_id.numtoa(10, &mut buff)].concat()
4444
}
4545

4646
/// Locks the execution of the function

common/primitives/src/schema.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ pub trait SchemaProvider<SchemaId> {
138138
/// This allows other Pallets to check validity of schema ids.
139139
pub trait SchemaValidator<SchemaId> {
140140
/// Checks that a collection of SchemaIds are all valid
141-
fn are_all_schema_ids_valid(schema_ids: &Vec<SchemaId>) -> bool;
141+
fn are_all_schema_ids_valid(schema_ids: &[SchemaId]) -> bool;
142142

143143
/// Set the schema counter for testing purposes.
144144
#[cfg(any(feature = "std", feature = "runtime-benchmarks", test))]

common/primitives/src/signatures.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ impl Into<UnifiedSignature> for MultiSignature {
254254
}
255255

256256
fn check_secp256k1_signature(signature: &[u8; 65], msg: &[u8; 32], signer: &AccountId32) -> bool {
257-
match sp_io::crypto::secp256k1_ecdsa_recover(signature, &msg) {
257+
match sp_io::crypto::secp256k1_ecdsa_recover(signature, msg) {
258258
Ok(pubkey) => {
259259
let mut hashed = sp_io::hashing::keccak_256(pubkey.as_ref());
260260
hashed[..12].fill(0);
@@ -284,13 +284,13 @@ fn check_ethereum_signature<L: Lazy<[u8]>>(
284284
};
285285

286286
// signature of ethereum prefixed message eip-191
287-
let message_prefixed = eth_message_hash(&msg.get());
288-
if verify_signature(&signature.as_ref(), &message_prefixed, signer) {
287+
let message_prefixed = eth_message_hash(msg.get());
288+
if verify_signature(signature.as_ref(), &message_prefixed, signer) {
289289
return true
290290
}
291291

292292
// signature of raw payload, compatible with polkadotJs signatures
293-
let hashed = sp_io::hashing::keccak_256(&msg.get());
293+
let hashed = sp_io::hashing::keccak_256(msg.get());
294294
verify_signature(signature.as_ref(), &hashed, signer)
295295
}
296296

@@ -306,10 +306,10 @@ mod tests {
306306
let msg = &b"test-message"[..];
307307
let (pair, _) = ecdsa::Pair::generate();
308308

309-
let signature = pair.sign(&msg);
309+
let signature = pair.sign(msg);
310310
let unified_sig = UnifiedSignature::from(signature);
311311
let unified_signer = UnifiedSigner::from(pair.public());
312-
assert_eq!(unified_sig.verify(msg, &unified_signer.into_account()), false);
312+
assert!(!unified_sig.verify(msg, &unified_signer.into_account()));
313313
}
314314

315315
#[test]
@@ -365,6 +365,6 @@ mod tests {
365365
.expect("invalid size"),
366366
);
367367
let unified_signer = UnifiedSigner::from(public_key);
368-
assert_eq!(unified_signature.verify(&payload[..], &unified_signer.into_account()), false);
368+
assert!(!unified_signature.verify(&payload[..], &unified_signer.into_account()));
369369
}
370370
}

common/primitives/src/utils.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,11 @@ pub mod as_hex_option {
6868
}
6969

7070
/// Deserializes a hexadecimal string into a `Vec<u8>`
71-
pub fn deserialize<'de, D: Deserializer<'de>>(
72-
deserializer: D,
73-
) -> Result<Option<Vec<u8>>, D::Error>
71+
pub fn deserialize<'de, D>(deserializer: D) -> Result<Option<Vec<u8>>, D::Error>
7472
where
7573
D: Deserializer<'de>,
7674
{
77-
impl_serde::serialize::deserialize(deserializer).map(|r| Some(r))
75+
impl_serde::serialize::deserialize(deserializer).map(Some)
7876
}
7977
}
8078
/// Handle serializing and deserializing from `Vec<u8>` to a UTF-8 string
@@ -84,7 +82,7 @@ pub mod as_string {
8482
use serde::{ser::Error, Deserialize, Deserializer, Serialize, Serializer};
8583

8684
/// Serializes a `Vec<u8>` into a UTF-8 string
87-
pub fn serialize<S: Serializer>(bytes: &Vec<u8>, serializer: S) -> Result<S::Ok, S::Error> {
85+
pub fn serialize<S: Serializer>(bytes: &[u8], serializer: S) -> Result<S::Ok, S::Error> {
8886
std::str::from_utf8(bytes)
8987
.map_err(|e| S::Error::custom(format!("Debug buffer contains invalid UTF8: {}", e)))?
9088
.serialize(serializer)
@@ -129,8 +127,8 @@ pub mod as_string_option {
129127
}
130128
}
131129

132-
const PREFIX: &'static str = "<Bytes>";
133-
const POSTFIX: &'static str = "</Bytes>";
130+
const PREFIX: &str = "<Bytes>";
131+
const POSTFIX: &str = "</Bytes>";
134132

135133
/// Wraps `PREFIX` and `POSTFIX` around a `Vec<u8>`
136134
/// Returns `PREFIX` ++ `data` ++ `POSTFIX`

node/cli/src/benchmarking.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@ use sp_keyring::Sr25519Keyring;
1414
use sp_runtime::{OpaqueExtrinsic, SaturatedConversion};
1515

1616
use pallet_balances::Call as BalancesCall;
17-
use pallet_msa;
1817
use sp_inherents::InherentDataProvider;
1918
#[allow(deprecated)]
2019
use sp_runtime::traits::transaction_extension::AsTransactionExtension;
21-
use sp_timestamp;
2220
use std::{sync::Arc, time::Duration};
2321

2422
/// Generates extrinsics for the `benchmark overhead` command.
@@ -88,11 +86,8 @@ impl frame_benchmarking_cli::ExtrinsicBuilder for TransferKeepAliveBuilder {
8886
let extrinsic: OpaqueExtrinsic = create_benchmark_extrinsic(
8987
self.client.as_ref(),
9088
acc,
91-
BalancesCall::transfer_keep_alive {
92-
dest: self.dest.clone().into(),
93-
value: self.value.into(),
94-
}
95-
.into(),
89+
BalancesCall::transfer_keep_alive { dest: self.dest.clone().into(), value: self.value }
90+
.into(),
9691
nonce,
9792
)
9893
.into();

node/cli/src/command.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ impl IdentifyChain for dyn sc_service::ChainSpec {
4747

4848
impl PartialEq for ChainIdentity {
4949
fn eq(&self, other: &Self) -> bool {
50+
#[allow(clippy::match_like_matches_macro)]
5051
match (self, other) {
5152
(ChainIdentity::Frequency, ChainIdentity::Frequency) => true,
5253
(ChainIdentity::FrequencyPaseo, ChainIdentity::FrequencyPaseo) => true,
@@ -66,18 +67,17 @@ impl<T: sc_service::ChainSpec + 'static> IdentifyChain for T {
6667
fn load_spec(id: &str) -> std::result::Result<Box<dyn ChainSpec>, String> {
6768
match id {
6869
#[cfg(feature = "runtime-benchmarks")]
69-
"frequency-bench" => return Ok(Box::new(chain_spec::frequency::benchmark_mainnet_config())),
70+
"frequency-bench" => Ok(Box::new(chain_spec::frequency::benchmark_mainnet_config())),
7071
#[cfg(feature = "frequency")]
71-
"frequency" => return Ok(Box::new(chain_spec::frequency::load_frequency_spec())),
72+
"frequency" => Ok(Box::new(chain_spec::frequency::load_frequency_spec())),
7273
#[cfg(feature = "frequency-no-relay")]
73-
"dev" | "frequency-no-relay" =>
74-
return Ok(Box::new(chain_spec::frequency_dev::development_config())),
74+
"dev" | "frequency-no-relay" => Ok(Box::new(chain_spec::frequency_dev::development_config())),
7575
#[cfg(feature = "frequency-local")]
7676
"frequency-paseo-local" =>
77-
return Ok(Box::new(chain_spec::frequency_paseo::local_paseo_testnet_config())),
77+
Ok(Box::new(chain_spec::frequency_paseo::local_paseo_testnet_config())),
7878
#[cfg(feature = "frequency-testnet")]
7979
"frequency-testnet" | "frequency-paseo" | "paseo" | "testnet" =>
80-
return Ok(Box::new(chain_spec::frequency_paseo::load_frequency_paseo_spec())),
80+
Ok(Box::new(chain_spec::frequency_paseo::load_frequency_paseo_spec())),
8181
path => {
8282
if path.is_empty() {
8383
if cfg!(feature = "frequency") {
@@ -122,9 +122,7 @@ fn load_spec(id: &str) -> std::result::Result<Box<dyn ChainSpec>, String> {
122122
if ChainIdentity::Frequency == spec.identify() {
123123
#[cfg(feature = "frequency")]
124124
{
125-
return Ok(Box::new(chain_spec::frequency::ChainSpec::from_json_file(
126-
path_buf,
127-
)?));
125+
Ok(Box::new(chain_spec::frequency::ChainSpec::from_json_file(path_buf)?))
128126
}
129127
#[cfg(not(feature = "frequency"))]
130128
return Err("Frequency runtime is not available.".into());
@@ -240,13 +238,12 @@ impl SubstrateCli for RelayChainCli {
240238
match id {
241239
// TODO: Remove once on a Polkadot-SDK with Paseo-Local
242240
#[cfg(feature = "frequency-local")]
243-
"paseo-local" => return Ok(Box::new(chain_spec::frequency_paseo::load_paseo_local_spec())),
241+
"paseo-local" => Ok(Box::new(chain_spec::frequency_paseo::load_paseo_local_spec())),
244242
// TODO: Remove once on a Polkadot-SDK with Paseo
245243
#[cfg(feature = "frequency-testnet")]
246-
"paseo" => return Ok(Box::new(chain_spec::frequency_paseo::load_paseo_spec())),
247-
_ =>
248-
return polkadot_cli::Cli::from_iter([RelayChainCli::executable_name()].iter())
249-
.load_spec(id),
244+
"paseo" => Ok(Box::new(chain_spec::frequency_paseo::load_paseo_spec())),
245+
_ => polkadot_cli::Cli::from_iter([RelayChainCli::executable_name()].iter())
246+
.load_spec(id),
250247
}
251248
}
252249
}
@@ -346,9 +343,9 @@ pub fn run() -> Result<()> {
346343
))
347344
})
348345
} else {
349-
return Err("Benchmarking wasn't enabled when building the node. \
346+
Err("Benchmarking wasn't enabled when building the node. \
350347
You can enable it with `--features runtime-benchmarks`."
351-
.into());
348+
.into())
352349
},
353350
BenchmarkCmd::Block(cmd) => runner.sync_run(|config| {
354351
let partials = new_partial(&config, false)?;

node/cli/src/run_as_parachain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub fn run_as_parachain(cli: Cli) -> sc_service::Result<(), sc_cli::Error> {
3737
info!("Parachain id: {:?}", id);
3838
info!("Is collating: {}", if config.role.is_authority() { "yes" } else { "no" });
3939

40-
return frequency_service::service::start_parachain_node(
40+
frequency_service::service::start_parachain_node(
4141
config,
4242
polkadot_config,
4343
collator_options,

0 commit comments

Comments
 (0)