Skip to content

Commit

Permalink
fix(l2): add clippy suggestions (#951)
Browse files Browse the repository at this point in the history
**Motivation**

Clippy was throwing some warnings, applying it suggestions.

**Description**

Command:
```sh
cargo clippy --all-targets --all-features --workspace -- -D warnings
```

Output to Fix:
```
warning: it looks like you're manually copying between slices
  --> cmd/ethereum_rust_l2/src/commands/test.rs:77:5
   |
77 | /     for i in 0..64 {
78 | |         buffer[i] = public_key[i + 1];
79 | |     }
   | |_____^ help: try replacing the loop by: `buffer.copy_from_slice(&public_key[1..(64 + 1)]);`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_memcpy
   = note: `#[warn(clippy::manual_memcpy)]` on by default

warning: unnecessary `if let` since only the `Ok` variant of the iterator element is used
   --> cmd/ethereum_rust_l2/src/commands/test.rs:133:21
    |
133 |                       for line in lines {
    |                       ^           ----- help: try: `lines.flatten()`
    |  _____________________|
    | |
134 | |                         if let Ok(pk) = line {
135 | |                             let thread = tokio::spawn(transfer_from(
136 | |                                 pk,
...   |
144 | |                         }
145 | |                     }
    | |_____________________^
    |
help: ...and remove the `if let` statement in the for loop
   --> cmd/ethereum_rust_l2/src/commands/test.rs:134:25
    |
134 | /                         if let Ok(pk) = line {
135 | |                             let thread = tokio::spawn(transfer_from(
136 | |                                 pk,
137 | |                                 to_address.clone(),
...   |
143 | |                             threads.push(thread);
144 | |                         }
    | |_________________________^
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#manual_flatten
    = note: `#[warn(clippy::manual_flatten)]` on by default

warning: using `clone` on type `H160` which implements the `Copy` trait
   --> cmd/ethereum_rust_l2/src/commands/test.rs:137:33
    |
137 | ...                   to_address.clone(),
    |                       ^^^^^^^^^^^^^^^^^^ help: try removing the `clone` call: `to_address`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy
    = note: `#[warn(clippy::clone_on_copy)]` on by default
```
  • Loading branch information
fborello-lambda authored Oct 23, 2024
1 parent e9c7ce4 commit 80f6448
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions cmd/ethereum_rust_l2/src/commands/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ async fn transfer_from(

let mut buffer = [0u8; 64];
let public_key = libsecp256k1::PublicKey::from_secret_key(&private_key).serialize();
for i in 0..64 {
buffer[i] = public_key[i + 1];
}
buffer.copy_from_slice(&public_key[1..]);

let address = H160::from(keccak(buffer));
let nonce = client.get_nonce(address).await.unwrap();
Expand Down Expand Up @@ -130,18 +128,16 @@ impl Command {
println!("Sending to: {to_address:#x}");

let mut threads = vec![];
for line in lines {
if let Ok(pk) = line {
let thread = tokio::spawn(transfer_from(
pk,
to_address.clone(),
value,
iterations,
verbose,
cfg.clone(),
));
threads.push(thread);
}
for pk in lines.map_while(Result::ok) {
let thread = tokio::spawn(transfer_from(
pk,
to_address,
value,
iterations,
verbose,
cfg.clone(),
));
threads.push(thread);
}

let mut retries = 0;
Expand Down

0 comments on commit 80f6448

Please sign in to comment.