From 7ad744e7b3cf6f6cc3878106dc7eb8ac505f232b Mon Sep 17 00:00:00 2001 From: Maksim Ramanenkau Date: Mon, 6 May 2024 13:02:49 +0400 Subject: [PATCH] Enable Clippy (#324) ### Description 1. Use the `stable` channel since `nightly` doesn't work for Clippy. 2. Keep `nightly` for `rustfmt` since it uses unstable features. 3. Execute `cargo +nightly-2024-03-12 fmt` ### Types of Changes - [x] Tech Debt (Code improvements) - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Dependency upgrade (A change in substrate or any 3rd party crate version) ### Migrations and Hooks - [ ] This change requires a runtime migration. - [ ] Modifies `on_initialize` - [ ] Modifies `on_finalize` ### Checklist - [x] Change has been tested locally. - [ ] Change adds / updates tests. - [ ] Changelog doc updated. --- .github/workflows/ci.yaml | 14 +++++++------- README.md | 2 +- node/cli/src/command.rs | 4 ++-- node/service/src/lib.rs | 4 ++-- pallets/ddc-customers/src/lib.rs | 3 ++- pallets/ddc-nodes/src/lib.rs | 4 ++-- pallets/ddc-staking/src/lib.rs | 10 +++++----- rust-toolchain.toml | 4 ++-- scripts/init.sh | 4 ++-- scripts/pre-commit.sh | 2 +- 10 files changed, 26 insertions(+), 25 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 69a868ba7..776ae796f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -21,7 +21,7 @@ jobs: steps: # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v3 - - name: Install nightly toolchain + - name: Install toolchain uses: actions-rs/toolchain@v1 with: toolchain: nightly-2024-03-12 @@ -41,10 +41,10 @@ jobs: - uses: actions/checkout@v3 - name: Install linux dependencies run: sudo apt update && sudo apt install -y cargo clang libssl-dev llvm libudev-dev protobuf-compiler - - name: Install nightly toolchain + - name: Install toolchain uses: actions-rs/toolchain@v1 with: - toolchain: nightly-2024-03-12 + toolchain: 1.77.0 override: true target: wasm32-unknown-unknown - name: Rust Cache @@ -71,10 +71,10 @@ jobs: - uses: actions/checkout@v3 - name: Install linux dependencies run: sudo apt update && sudo apt install -y cargo clang libssl-dev llvm libudev-dev protobuf-compiler - - name: Install nightly toolchain + - name: Install toolchain uses: actions-rs/toolchain@v1 with: - toolchain: nightly-2024-03-12 + toolchain: 1.77.0 override: true target: wasm32-unknown-unknown components: clippy @@ -94,10 +94,10 @@ jobs: - uses: actions/checkout@v3 - name: Install linux dependencies run: sudo apt update && sudo apt install -y cargo clang libssl-dev llvm libudev-dev protobuf-compiler - - name: Install nightly toolchain + - name: Install toolchain uses: actions-rs/toolchain@v1 with: - toolchain: nightly-2024-03-12 + toolchain: 1.77.0 override: true target: wasm32-unknown-unknown - name: Rust Cache diff --git a/README.md b/README.md index ff20ca694..596133ec7 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ First, complete the [basic Rust setup instructions](./docs/rust-setup.md). Use the following command to build the node without launching it: ```sh -cargo +nightly-2024-03-12 build --release +cargo +1.77.0 build --release ``` ## Run diff --git a/node/cli/src/command.rs b/node/cli/src/command.rs index f5d564c3d..5720c980e 100644 --- a/node/cli/src/command.rs +++ b/node/cli/src/command.rs @@ -138,14 +138,14 @@ pub fn run() -> sc_cli::Result<()> { if !cfg!(feature = "runtime-benchmarks") { return Err("Runtime benchmarking wasn't enabled when building the node. \ You can enable it with `--features runtime-benchmarks`." - .into()) + .into()); } #[cfg(feature = "cere-dev-native")] if chain_spec.is_cere_dev() { return runner.sync_run(|config| { cmd.run::(config) - }) + }); } #[cfg(not(feature = "cere-native"))] diff --git a/node/service/src/lib.rs b/node/service/src/lib.rs index 7beb0d9d4..374732ae5 100644 --- a/node/service/src/lib.rs +++ b/node/service/src/lib.rs @@ -286,7 +286,7 @@ pub fn build_full( disable_hardware_benchmarks, |_, _| (), ) - .map(|full| full.with_client(Client::CereDev)) + .map(|full| full.with_client(Client::CereDev)); } #[cfg(feature = "cere-native")] @@ -635,7 +635,7 @@ pub fn new_chain_ops( > { #[cfg(feature = "cere-dev-native")] if config.chain_spec.is_cere_dev() { - return chain_ops!(config; cere_dev_runtime, CereDevExecutorDispatch, CereDev) + return chain_ops!(config; cere_dev_runtime, CereDevExecutorDispatch, CereDev); } #[cfg(feature = "cere-native")] diff --git a/pallets/ddc-customers/src/lib.rs b/pallets/ddc-customers/src/lib.rs index 1a22a5905..7e8876693 100644 --- a/pallets/ddc-customers/src/lib.rs +++ b/pallets/ddc-customers/src/lib.rs @@ -245,6 +245,7 @@ pub mod pallet { } } + #[allow(unused_must_use)] #[pallet::genesis_build] impl BuildGenesisConfig for GenesisConfig { fn build(&self) { @@ -612,7 +613,7 @@ pub mod pallet { } if unlocking_balance >= value { - break + break; } } diff --git a/pallets/ddc-nodes/src/lib.rs b/pallets/ddc-nodes/src/lib.rs index a8220b2bd..4f0e8aba0 100644 --- a/pallets/ddc-nodes/src/lib.rs +++ b/pallets/ddc-nodes/src/lib.rs @@ -185,7 +185,7 @@ pub mod pallet { match node { Node::Storage(storage_node) => { if StorageNodes::::contains_key(&storage_node.pub_key) { - return Err(NodeRepositoryError::StorageNodeAlreadyExists) + return Err(NodeRepositoryError::StorageNodeAlreadyExists); } StorageNodes::::insert(storage_node.pub_key.clone(), storage_node); Ok(()) @@ -206,7 +206,7 @@ pub mod pallet { match node { Node::Storage(storage_node) => { if !StorageNodes::::contains_key(&storage_node.pub_key) { - return Err(NodeRepositoryError::StorageNodeDoesNotExist) + return Err(NodeRepositoryError::StorageNodeDoesNotExist); } StorageNodes::::insert(storage_node.pub_key.clone(), storage_node); }, diff --git a/pallets/ddc-staking/src/lib.rs b/pallets/ddc-staking/src/lib.rs index 311fdc74d..8d42e0316 100644 --- a/pallets/ddc-staking/src/lib.rs +++ b/pallets/ddc-staking/src/lib.rs @@ -604,7 +604,7 @@ pub mod pallet { ensure!(current_cluster == cluster_id, Error::::AlreadyInRole); // Cancel previous "chill" attempts Self::reset_chilling(&controller); - return Ok(()) + return Ok(()); } else { // Can't participate in new Storage network if provider hasn't left the previous // cluster yet @@ -646,13 +646,13 @@ pub mod pallet { .map_err(Into::>::into)?; (cluster, chill_delay) } else { - return Ok(()) // node is already chilling or leaving the cluster + return Ok(()); // node is already chilling or leaving the cluster }; if delay == BlockNumberFor::::from(0u32) { // No delay is set, so we can chill right away. Self::chill_stash(&ledger.stash); - return Ok(()) + return Ok(()); } let can_chill_from = current_block.defensive_saturating_add(delay); @@ -660,13 +660,13 @@ pub mod pallet { None => { // No previous declarations of desire to chill. Note it to allow chilling soon. Self::chill_stash_soon(&ledger.stash, &controller, cluster, can_chill_from); - return Ok(()) + return Ok(()); }, Some(chilling) if can_chill_from < chilling => { // Time to chill is not reached yet, but it is allowed to chill earlier. Update // to allow chilling sooner. Self::chill_stash_soon(&ledger.stash, &controller, cluster, can_chill_from); - return Ok(()) + return Ok(()); }, Some(chilling) if chilling > current_block => Err(Error::::TooEarly)?, Some(_) => (), diff --git a/rust-toolchain.toml b/rust-toolchain.toml index b358f6e8e..aea318803 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] -channel = "nightly-2024-03-12" -components = ["clippy", "rustfmt"] +channel = "1.77.0" +components = ["clippy"] targets = ["wasm32-unknown-unknown"] diff --git a/scripts/init.sh b/scripts/init.sh index d7eaa58b2..105339203 100755 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -4,9 +4,9 @@ set -e echo "*** Initializing WASM build environment" -rustup install nightly-2024-03-12 +rustup install 1.77.0 -rustup target add wasm32-unknown-unknown --toolchain nightly-2024-03-12 +rustup target add wasm32-unknown-unknown --toolchain 1.77.0 ln -sf $PWD/scripts/pre-commit.sh $PWD/.git/hooks/pre-commit || true ln -sf $PWD/scripts/pre-push.sh $PWD/.git/hooks/pre-push || true diff --git a/scripts/pre-commit.sh b/scripts/pre-commit.sh index a01d1ba34..ee7aec9f9 100755 --- a/scripts/pre-commit.sh +++ b/scripts/pre-commit.sh @@ -2,7 +2,7 @@ # Prevent committing badly formatted code -cargo fmt -- --check +cargo +nightly-2024-03-12 fmt -- --check if [ $? -ne 0 ]; then echo "Run \`cargo fmt\` to fix formatting issues before committing." exit 1