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

bitcoind_test: Fix clippy #686

Merged
merged 13 commits into from
May 16, 2024
Merged

Conversation

tcharding
Copy link
Member

All the clippy patches rom #682, only touches bitcoind_test.

Remove build error:

  error: casting integer literal to `u8` is unnecessary
@@ -86,8 +86,8 @@ fn setup_keys(
let mut x_only_keypairs = vec![];
let mut x_only_pks = vec![];

for i in 0..n {
let keypair = bitcoin::secp256k1::Keypair::from_secret_key(&secp_sign, &sks[i]);
for sk in sks.iter().take(n) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In b328736:

iter and take continue to be unnecessary

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its like I didn't even read your review the first time :(

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix, and lol "continue to be unnecessary" - love it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what was the original intention of the code but as it reads the take(n) is required because n is a function parameter so we can't just iterate over all of sk.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the iteration above we construct sk by looping n times and pushing stuff onto sk.

We could add a debug_assert that sk.len() equals n if it makes you nervous.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, I did not read the code properly. Used for sk in sks { as suggested.

@storopoli
Copy link
Contributor

Should we squash all these commits down?

@apoelstra
Copy link
Member

@storopoli I see no particular reason to. They are all independent and compile and pass all tests (I assume -- I have not tested them because the second one needs to be changed).

@tcharding
Copy link
Member Author

I go to painful lengths to put all these changes separately so that its quick and easy for reviewers to review them [0]. Also its easy to drop any particular patch if a reviewer doesn't like it. Even the commit messages should be so uniform that they are easy to read quickly (and mechanical for me to write).

[0] Definitely pull me up if there are changes in the wrong place.

tcharding added 12 commits May 16, 2024 11:35
Clear clippy warning:

  the loop variable `i` is only used to index `sks`
Clippy emits:

  warning: redundant field names in struct initialization

As suggested, remove redundant field names.
Clippy emits:

  warning: single-character string constant used as pattern

As suggested, use single quotes.
Clippy emits:

  warning: manual implementation of an assign operation

As suggested, use += operator.
Clippy emits:

  warning: unneeded `return` statement

As suggested, remove unneeded return statement.
Clippy emits:

 warning: field assignment outside of initializer for an instance
 created with Default::default()

As suggested use `..Default::default()` instead of mutating.
Clippy emits:

  warning: this expression creates a reference which is immediately
  dereferenced by the compiler

As suggested, remove explicit reference.
Clippy emits:

  warning: useless conversion to the same type:
  `setup::miniscript::bitcoin::absolute::LockTime`

As suggested, remove useless conversion.
Found with clippy, just use `Copy`.
Clippy emits:

  warning: use of `expect` followed by a function call

As suggested, use `unwrap_or_else` with `panic!`.
Clippy emits:

  warning: redundant pattern matching, consider using `is_err()`

As suggested, use `is_err()`.
@tcharding
Copy link
Member Author

Neat, TIL:

for f in foo desugars to for f in foo.into_iter() and for f in &foo desugars to for f in foo.iter()

Copy link
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK b9a207b

@apoelstra apoelstra merged commit b507ff6 into rust-bitcoin:master May 16, 2024
7 checks passed
@apoelstra
Copy link
Member

Oops, that utACk should have been a full ACK. I did test every commit, it just took some manual prodding to avoid opening too many files at once.

@tcharding tcharding deleted the 05-15-clippy branch May 16, 2024 21:59
@tcharding
Copy link
Member Author

Is there anything we can do about bot accounts triggering notifications like this @ErnestoLara idiot above? (Mentioning him incase he is a real person :)

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

Successfully merging this pull request may close these issues.

3 participants