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

New clippy nightly lints #34626

Closed
brooksprumo opened this issue Jan 2, 2024 · 3 comments
Closed

New clippy nightly lints #34626

brooksprumo opened this issue Jan 2, 2024 · 3 comments

Comments

@brooksprumo
Copy link
Contributor

brooksprumo commented Jan 2, 2024

Problem

There are new clippy lints in nightly (as of version nightly-aarch64-apple-darwin - rustc 1.77.0-nightly (e51e98dde 2023-12-31)) that prevent us from upgrading our nightly version of Rust to the latest. Usually we upgrade both stable and nightly at the same time, but in #34607 we only upgraded stable.

All the new lints

solana-zk-token-sdk

warning: writing `&Vec` instead of `&[_]` involves a new object where a slice will do
  --> zk-token-sdk/src/instruction/batched_range_proof/mod.rs:62:22
   |
62 |         commitments: &Vec<&PedersenCommitment>,
   |                      ^^^^^^^^^^^^^^^^^^^^^^^^^ help: change this to: `&[&PedersenCommitment]`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg
   = note: `#[warn(clippy::ptr_arg)]` on by default

warning: writing `&Vec` instead of `&[_]` involves a new object where a slice will do
  --> zk-token-sdk/src/instruction/batched_range_proof/mod.rs:63:18
   |
63 |         amounts: &Vec<u64>,
   |                  ^^^^^^^^^ help: change this to: `&[u64]`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg

warning: writing `&Vec` instead of `&[_]` involves a new object where a slice will do
  --> zk-token-sdk/src/instruction/batched_range_proof/mod.rs:64:22
   |
64 |         bit_lengths: &Vec<usize>,
   |                      ^^^^^^^^^^^ help: change this to: `&[usize]`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg

warning: writing `&Vec` instead of `&[_]` involves a new object where a slice will do
  --> zk-token-sdk/src/instruction/batched_range_proof/mod.rs:65:19
   |
65 |         openings: &Vec<&PedersenOpening>,
   |                   ^^^^^^^^^^^^^^^^^^^^^^ help: change this to: `&[&PedersenOpening]`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg

    Checking solana-clap-utils v1.18.0 (/Users/brooks/src/solana/clap-utils)
warning: `solana-zk-token-sdk` (lib) generated 4 warnings

solana-bpf-loader-program

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`
   --> programs/bpf_loader/src/syscalls/mem_ops.rs:227:39
    |
227 |           |s1_addr, s2_addr, chunk_len| {
    |  _______________________________________^
228 | |             let res = unsafe {
229 | |                 let s1 = slice::from_raw_parts(s1_addr, chunk_len);
230 | |                 let s2 = slice::from_raw_parts(s2_addr, chunk_len);
...   |
240 | |             Ok(0)
241 | |         },
    | |_________^
    |
    = 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: `solana-bpf-loader-program` (lib) generated 1 warning

solana-accounts-db

warning: this `let...else` may be rewritten with the `?` operator
  --> accounts-db/src/rolling_bit_field/iterators.rs:36:13
   |
36 | /             let Some(bit) = self.bit_range.next() else {
37 | |                 return None;
38 | |             };
   | |______________^ help: replace it with: `let bit = self.bit_range.next()?;`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#question_mark
   = note: `#[warn(clippy::question_mark)]` on by default

    Checking solana-rpc-client-api v1.18.0 (/Users/brooks/src/solana/rpc-client-api)
warning: `solana-accounts-db` (lib) generated 1 warning

solana-runtime

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`
   --> runtime/src/accounts/mod.rs:483:82
    |
483 |       let min_balance = match get_system_account_kind(payer_account).ok_or_else(|| {
    |  __________________________________________________________________________________^
484 | |         error_counters.invalid_account_for_fee += 1;
485 | |         TransactionError::InvalidAccountForFee
486 | |     })? {
    | |_____^
    |
    = 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: this `let...else` may be rewritten with the `?` operator
    --> runtime/src/bank.rs:3093:21
     |
3093 | /                     let Some(vote_account) = get_vote_account(&vote_pubkey) else {
3094 | |                         return None;
3095 | |                     };
     | |______________________^ help: replace it with: `let vote_account = get_vote_account(&vote_pubkey)?;`
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#question_mark
     = note: `#[warn(clippy::question_mark)]` on by default

warning: this `let...else` may be rewritten with the `?` operator
    --> runtime/src/bank.rs:4778:17
     |
4778 | /                 let Some((_, account)) = accounts.get(i) else {
4779 | |                     return None;
4780 | |                 };
     | |__________________^ help: replace it with: `let (_, account) = accounts.get(i)?;`
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#question_mark

    Checking solana-bench-streamer v1.18.0 (/Users/brooks/src/solana/bench-streamer)
warning: `solana-runtime` (lib) generated 3 warnings

solana-rpc

warning: writing `&mut Vec` instead of `&mut [_]` involves a new object where a slice will do
   --> rpc/src/optimistically_confirmed_bank_tracker.rs:238:16
    |
238 |         roots: &mut Vec<Slot>,
    |                ^^^^^^^^^^^^^^ help: change this to: `&mut [Slot]`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg
    = note: `#[warn(clippy::ptr_arg)]` on by default

warning: `solana-rpc` (lib) generated 1 warning

solana-core

warning: writing `&Vec` instead of `&[_]` involves a new object where a slice will do
   --> core/src/banking_stage/consumer.rs:153:29
    |
153 |         packets_to_process: &Vec<Arc<ImmutableDeserializedPacket>>,
    |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: change this to: `&[Arc<ImmutableDeserializedPacket>]`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg
    = note: `#[warn(clippy::ptr_arg)]` on by default

warning: `solana-core` (lib) generated 1 warning
warning: unit tests in doctest are not executed
  --> core/tests/fork-selection.rs:15:5
   |
15 |   //! #[test]
   |  _____^
16 | | //! #[ignore]
17 | | //! fn test_all_partitions() {
   | |__________________________^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#test_attr_in_doctest
   = note: `#[warn(clippy::test_attr_in_doctest)]` on by default

warning: `solana-core` (test "fork-selection") generated 1 warning

solana-ledger-tool

warning: `flatten()` will run forever if the iterator repeatedly produces an `Err`
    --> ledger-tool/src/main.rs:2649:39
     |
2649 |                 for line in f.lines().flatten() {
     |                                       ^^^^^^^^^ help: replace with: `map_while(Result::ok)`
     |
note: this expression returning a `std::io::Lines` may produce an infinite number of `Err` in case of a read error
    --> ledger-tool/src/main.rs:2649:29
     |
2649 |                 for line in f.lines().flatten() {
     |                             ^^^^^^^^^
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#lines_filter_map_ok
     = note: `#[warn(clippy::lines_filter_map_ok)]` on by default

warning: `solana-ledger-tool` (bin "solana-ledger-tool" test) generated 1 warning

solana-validator

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`
   --> validator/src/dashboard.rs:223:38
    |
223 |                       match async move {
    |  ______________________________________^
224 | |                         let rpc_addr = admin_client.rpc_addr().await?;
225 | |                         let start_time = admin_client.start_time().await?;
226 | |                         Ok::<_, jsonrpc_core_client::RpcError>((rpc_addr, start_time))
227 | |                     }
    | |_____________________^
    |
    = 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: `solana-validator` (lib) generated 1 warning

Proposed Solution

Fix the new warnings.

@brooksprumo
Copy link
Contributor Author

There are a few remaining lints left to fix.
@steviez would you be willing to fix the ones in ledger-tool?
@alessandrod would you be willing to fix the ones in bpf_loader?
The specific lints for both are in the PR's description, under the "All the new lints" section.

As you likely know, this is not high priority.

@steviez
Copy link
Contributor

steviez commented Jan 3, 2024

@steviez would you be willing to fix the ones in ledger-tool?

Can do, looks like it should be pretty quick so I can knock it at some point today

@brooksprumo
Copy link
Contributor Author

Closing. All the lints have now been resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants