Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solve cargo-clippy warnings #562

Open
3 tasks
marcelstanley opened this issue Aug 13, 2024 · 0 comments
Open
3 tasks

Solve cargo-clippy warnings #562

marcelstanley opened this issue Aug 13, 2024 · 0 comments
Milestone

Comments

@marcelstanley
Copy link
Collaborator

marcelstanley commented Aug 13, 2024

📚 Context

As of 1.5.1, running cargo clippy -- -A clippy::module_inception from offchain/ results in:

offchain$ cargo clippy -- -A clippy::module_inception
warning: assigning the result of `Clone::clone()` may be inefficient
  --> rollups-events/src/broker/indexer.rs:87:13
   |
87 |             state.inputs_last_id = event.id.clone();
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `state.inputs_last_id.clone_from(&event.id)`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assigning_clones
   = note: `#[warn(clippy::assigning_clones)]` on by default

warning: assigning the result of `Clone::clone()` may be inefficient
  --> rollups-events/src/broker/indexer.rs:99:13
   |
99 |             state.outputs_last_id = event.id.clone();
   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `clone_from()`: `state.outputs_last_id.clone_from(&event.id)`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#assigning_clones

warning: `rollups-events` (lib) generated 2 warnings (run `cargo clippy --fix --lib -p rollups-events` to apply 2 suggestions)
warning: item has both inner and outer attributes
 --> /home/marcel/development/cartesi/rollups-node/offchain/target/debug/build/contracts-e6be818570e43ef9/out/input_box.rs:2:1
  |
2 | / #[allow(clippy::too_many_arguments, non_camel_case_types)]
3 | | pub mod input_box {
4 | |     #![allow(clippy::enum_variant_names)]
5 | |     #![allow(dead_code)]
6 | |     #![allow(clippy::type_complexity)]
7 | |     #![allow(unused_imports)]
  | |_____________________________^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#mixed_attributes_style
  = note: `#[warn(clippy::mixed_attributes_style)]` on by default

warning: item has both inner and outer attributes
 --> /home/marcel/development/cartesi/rollups-node/offchain/target/debug/build/contracts-e6be818570e43ef9/out/authority.rs:2:1
  |
2 | / #[allow(clippy::too_many_arguments, non_camel_case_types)]
3 | | pub mod authority {
4 | |     #![allow(clippy::enum_variant_names)]
5 | |     #![allow(dead_code)]
6 | |     #![allow(clippy::type_complexity)]
7 | |     #![allow(unused_imports)]
  | |_____________________________^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#mixed_attributes_style

warning: item has both inner and outer attributes
 --> /home/marcel/development/cartesi/rollups-node/offchain/target/debug/build/contracts-e6be818570e43ef9/out/history.rs:2:1
  |
2 | / #[allow(clippy::too_many_arguments, non_camel_case_types)]
3 | | pub mod history {
4 | |     #![allow(clippy::enum_variant_names)]
5 | |     #![allow(dead_code)]
6 | |     #![allow(clippy::type_complexity)]
7 | |     #![allow(unused_imports)]
  | |_____________________________^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#mixed_attributes_style

warning: item has both inner and outer attributes
 --> /home/marcel/development/cartesi/rollups-node/offchain/target/debug/build/contracts-e6be818570e43ef9/out/cartesi_dapp.rs:2:1
  |
2 | / #[allow(clippy::too_many_arguments, non_camel_case_types)]
3 | | pub mod cartesi_d_app {
4 | |     #![allow(clippy::enum_variant_names)]
5 | |     #![allow(dead_code)]
6 | |     #![allow(clippy::type_complexity)]
7 | |     #![allow(unused_imports)]
  | |_____________________________^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#mixed_attributes_style

warning: `contracts` (lib) generated 4 warnings
warning: called `map(..).flatten()` on `Option`
   --> types/src/blockchain_config.rs:128:18
    |
128 |                   .map(|c| c.address)
    |  __________________^
129 | |                 .flatten());
    | |__________________________^ help: try replacing `map` with `and_then` and remove the `.flatten()`: `and_then(|c| c.address)`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#map_flatten
    = note: `#[warn(clippy::map_flatten)]` on by default

warning: called `map(..).flatten()` on `Option`
   --> types/src/blockchain_config.rs:133:18
    |
133 |                   .map(|c| c.address)
    |  __________________^
134 | |                 .flatten());
    | |__________________________^ help: try replacing `map` with `and_then` and remove the `.flatten()`: `and_then(|c| c.address)`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#map_flatten

warning: called `map(..).flatten()` on `Option`
   --> types/src/blockchain_config.rs:138:18
    |
138 |                   .map(|c| c.address)
    |  __________________^
139 | |                 .flatten());
    | |__________________________^ help: try replacing `map` with `and_then` and remove the `.flatten()`: `and_then(|c| c.address)`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#map_flatten

warning: `types` (lib) generated 3 warnings (run `cargo clippy --fix --lib -p types` to apply 3 suggestions)
warning: in a `match` scrutinee, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a `let`
  --> graphql-server/src/http.rs:67:17
   |
67 |           move || {
   |  _________________^
68 | |             let res =
69 | |                 query.execute_sync(&http_context.schema, &http_context.context);
70 | |             serde_json::to_string(&res)
71 | |         },
   | |_________^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#blocks_in_conditions
   = note: `#[warn(clippy::blocks_in_conditions)]` on by default

warning: `graphql-server` (lib) generated 1 warning
warning: called `map(f)` on an `Option` value where `f` is a closure that returns the unit type `()`
  --> dispatcher/src/drivers/context.rs:81:9
   |
81 | //         self.last_finished_epoch.map(|last_finished_epoch| {
82 | ||             // Asserting that the calculated epoch comes after the last finished epoch.
83 | ||             // (If last_finished_epoch == None then we don't need the assertion.)
84 | ||             assert!(input_epoch > last_finished_epoch)
85 | ||         });
   | ||__________^- help: try: `if let Some(last_finished_epoch) = self.last_finished_epoch { ... }`
   |  |__________|
   |
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#option_map_unit_fn
   = note: `#[warn(clippy::option_map_unit_fn)]` on by default

warning: `dispatcher` (lib) generated 1 warning
warning: called `map(..).flatten()` on `Option`
   --> authority-claimer/src/checker.rs:126:14
    |
126 |               .map(|claims| claims.last()) // Maps to Option<Option<Claim>>
    |  ______________^
127 | |             .flatten() // Back to only one Option
    | |______________________^ help: try replacing `map` with `and_then` and remove the `.flatten()`: `and_then(|claims| claims.last())`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#map_flatten
    = note: `#[warn(clippy::map_flatten)]` on by default

warning: called `map(..).flatten()` on `Option`
  --> authority-claimer/src/config/contracts.rs:56:18
   |
56 |                   .map(|c| c.address)
   |  __________________^
57 | |                 .flatten());
   | |__________________________^ help: try replacing `map` with `and_then` and remove the `.flatten()`: `and_then(|c| c.address)`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#map_flatten

warning: called `map(..).flatten()` on `Option`
  --> authority-claimer/src/config/contracts.rs:61:18
   |
61 |                   .map(|c| c.address)
   |  __________________^
62 | |                 .flatten());
   | |__________________________^ help: try replacing `map` with `and_then` and remove the `.flatten()`: `and_then(|c| c.address)`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#map_flatten

warning: bound is defined in more than one place
  --> state-server/src/lib.rs:29:25
   |
29 | pub async fn run_server<F: Foldable<UserData = Mutex<UserData>> + 'static>(
   |                         ^
...
34 |     F: serde::ser::Serialize,
   |     ^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_bound_locations
   = note: `#[warn(clippy::multiple_bound_locations)]` on by default

warning: `authority-claimer` (lib) generated 3 warnings (run `cargo clippy --fix --lib -p authority-claimer` to apply 3 suggestions)
warning: `state-server` (lib) generated 1 warning
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.29s

✔️ Solution

Change code to remove warnings.

📈 Subtasks

  • Apply suggestions made by clippy
  • Address remaining warnings
  • Make sure everything works as expected
@marcelstanley marcelstanley converted this from a draft issue Aug 13, 2024
@marcelstanley marcelstanley added this to the 1.6 milestone Aug 13, 2024
@marcelstanley marcelstanley moved this to 📋 Backlog in Node Unit Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 📋 Backlog
Development

No branches or pull requests

1 participant