Skip to content

Conversation

@tcharding
Copy link
Member

@tcharding tcharding commented Jun 10, 2022

The first 8 patches clear clippy warnings. Next we add a CI job to run clippy. Finally we add a githooks directory that includes running clippy, also adds a section to the README on how to use the githooks. This is identical to the text in the open PR on rust-bitcoin that adds githooks without yet adding clippy.

Note: The new clippy CI job runs and is green :)

@tcharding tcharding mentioned this pull request Jun 10, 2022
apoelstra
apoelstra previously approved these changes Jun 10, 2022
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.

ACK 5551f2c

@apoelstra
Copy link
Member

Needs rebase now, sorry.

Clippy emits:

  warning: this import is redundant

This is a remnant of edition 2015, now we have edition 2018 we no longer
need this import statement.
Clippy emits:

  warning: statics have by default a `'static` lifetime

Static strings no longer need an explicit lifetime, remove it.
Clippy emits:

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

Remove the explicit reference.
@tcharding
Copy link
Member Author

No changes in force push, rebase only, there was a merge conflict in one of the unit tests in commit: 35d59e7 Remove explicit 'static lifetime.

elichai
elichai previously approved these changes Jun 16, 2022
Copy link
Member

@elichai elichai left a comment

Choose a reason for hiding this comment

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

ACK d81d2fe

# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# To enable this hook, rename this file to "pre-commit".
Copy link
Contributor

Choose a reason for hiding this comment

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

that's already the name of the file?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice catch, I modified the whole comment to better describe the hook. Thanks.

Copy link
Collaborator

@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

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

The exec should be fixed, I believe.

exec git diff-index --check --cached $against --

# Check that code lints cleanly.
exec cargo clippy --features=rand-std,recovery,lowmemory,global-context --all-targets -- -D warnings
Copy link
Collaborator

Choose a reason for hiding this comment

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

This doesn't work since exec replaces the process (just like the exec syscall) thus this exec never executes

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks man, seems I tested whitespace but not clippy before pushing this. Out of interest I tried removing both the execs and adding set -e but that did not work, I then tried the form cmd || exit 1 for both and that works.

src/context.rs Outdated
/// ```
#[allow(unused_mut)] // Unused when `rand-std` is not enabled.
#[allow(unused_mut)] // Unused when `rand-std` is not enabled.
#[allow(clippy::let_and_return)] // Triggers when `rand-std` is not enabled.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Perhaps cfg_attr to limit the scope? Not a big deal though.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice trick! I had to think about your suggestion for a bit then I worked it out

    #[cfg_attr(not(feature = "rand-std"), allow(clippy::let_and_return, unused_mut))]

For the second time today; thanks for the lesson :)

src/ecdsa/mod.rs Outdated
let le_counter = counter.to_le_bytes();
for (i, b) in le_counter.iter().enumerate() {
extra_entropy[i] = *b;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This whole chunk could be just extra_entropy[..4].copy_from_slice(&counter.to_le_bytes);

Also below (can't comment there) cast is probably better than as. extra_entropy.as_ptr().cast::<ffi::types::c_void>();

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 used both suggestions, I was unable to justify the as -> cast change in the commit log, can you explain why its better please, just for my learning?

apoelstra
apoelstra previously approved these changes Jun 16, 2022
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.

ACK d81d2fe

@apoelstra
Copy link
Member

Will hold off on merging since @Kixunil's nits look good (and the exec thing might be more than a nit)

@Kixunil
Copy link
Collaborator

Kixunil commented Jun 16, 2022

exec is definitely not a nit. It breaks the main purpose of this PR. :)

@apoelstra
Copy link
Member

Well, it breaks the main purpose of the pre-commit hook :) but the CI job is not affected. But yes, I see your point.

@tcharding tcharding dismissed stale reviews from apoelstra and elichai via fddca7c June 16, 2022 23:45
@tcharding tcharding force-pushed the 06-10-clippy branch 2 times, most recently from fddca7c to 6c6a577 Compare June 16, 2022 23:58
Since we bumped the MSRV we have `to_le_bytes` available now, use it
instead of `mem::transmute`.

Remove code comment suggesting to do exactly this and clear clippy
warning.

While we are at it, use `cast` instead of `as`.
We have a whole bunch of unsafe code that calls down to the FFI layer.
It would be nice to have clippy running on CI, these safety docs
warnings are prohibiting that. Until we can add the docs add a compiler
attribute to allow the lint.
Clippy emits:

  warning: returning the result of a `let` binding from a block

This is due to feature guarded code, add 'allow' attribute. Use
`cfg_attr` to restrict the allow to when it is needed. Add the already
present `unused_mut` inside the `cfg_attr` guard also.
Clippy emits:

  warning: manual implementation of `str::repeat` using iterators

As suggested, use `"a".repeats()`.
We are explicitly testing various boolean statements, tell clippy to
allow less than minimal statements.
In order to keep the codebase linting cleanly add a CI job to run
clippy.
Add `githooks` directory and:

- Copy the default pre-commit hook into new githooks directory
- Add a call to clippy to the pre-commit hook
- Add a section to the README instructing devs how to use the new
  githooks
@tcharding
Copy link
Member Author

Solid reviewing crew, thank you. Force push includes the various changes above.

Copy link
Collaborator

@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

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

ACK 65186e7

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.

ACK 65186e7

@apoelstra apoelstra merged commit a1ac3fb into rust-bitcoin:master Jun 17, 2022
@tcharding tcharding deleted the 06-10-clippy branch June 20, 2022 22:03
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.

ACK 65186e7

@apoelstra
Copy link
Member

Lol, sorry, I meant to test and ack 488.

chain-forgexcr45 added a commit to chain-forgexcr45/rust-secp256k1 that referenced this pull request Sep 28, 2025
65186e732ac229575afd83f5c11bfb794ebc3ca8 Add githooks (Tobin C. Harding)
6d76bd4a8952f0a03f204b8096eaf6f0dc5d40d3 Add clippy to CI (Tobin C. Harding)
9f1ebb93cba87f5d43702a138cdce658fbdd511d Allow nonminimal_bool in unit test (Tobin C. Harding)
685444c34252142a516c3f04c242c73c54c91e8d Use "a".repeats() instead of manual implementation (Tobin C. Harding)
42de876e01071e0992067b88c620667be5b1391b Allow let_and_return for feature guarded code (Tobin C. Harding)
d64132cd4b4c03bb08f33cc4f8415669414335b4 Allow missing_safety_doc (Tobin C. Harding)
2cb687fc6999bd38bd3949b0c981e6ffb221b5f9 Use to_le_bytes instead of mem::transmute (Tobin C. Harding)
c15b9d26997c062c8bb5f26a3ad8ba2f20a91244 Remove unneeded explicit reference (Tobin C. Harding)
35d59e7cc6954a0109191b2772f0f4a90197ef8c Remove explicit 'static lifetime (Tobin C. Harding)
1a582db16021e696effeb6080d1197a23c620cf2 Remove redundant import (Tobin C. Harding)

Pull request description:

  The first 8 patches clear clippy warnings. Next we add a CI job to run clippy. Finally we add a `githooks` directory that includes running clippy, also adds a section to the README on how to use the githooks. This is identical to the text in the [open PR](rust-bitcoin/rust-bitcoin#1044) on `rust-bitcoin` that adds githooks _without_ yet adding clippy.

  **Note**: The new clippy CI job runs and is green :)

ACKs for top commit:
  Kixunil:
    ACK 65186e732ac229575afd83f5c11bfb794ebc3ca8
  apoelstra:
    ACK 65186e732ac229575afd83f5c11bfb794ebc3ca8

Tree-SHA512: f70a157896ce2a83af8cfc10f2fbacc8f68256ac96ef7dec4d190aa72324b568d2267418eb4fe99099aeda5486957c31070943d7c209973859b7b9290676ccd7
william2332-limf added a commit to william2332-limf/rust-secp256k1 that referenced this pull request Oct 2, 2025
65186e732ac229575afd83f5c11bfb794ebc3ca8 Add githooks (Tobin C. Harding)
6d76bd4a8952f0a03f204b8096eaf6f0dc5d40d3 Add clippy to CI (Tobin C. Harding)
9f1ebb93cba87f5d43702a138cdce658fbdd511d Allow nonminimal_bool in unit test (Tobin C. Harding)
685444c34252142a516c3f04c242c73c54c91e8d Use "a".repeats() instead of manual implementation (Tobin C. Harding)
42de876e01071e0992067b88c620667be5b1391b Allow let_and_return for feature guarded code (Tobin C. Harding)
d64132cd4b4c03bb08f33cc4f8415669414335b4 Allow missing_safety_doc (Tobin C. Harding)
2cb687fc6999bd38bd3949b0c981e6ffb221b5f9 Use to_le_bytes instead of mem::transmute (Tobin C. Harding)
c15b9d26997c062c8bb5f26a3ad8ba2f20a91244 Remove unneeded explicit reference (Tobin C. Harding)
35d59e7cc6954a0109191b2772f0f4a90197ef8c Remove explicit 'static lifetime (Tobin C. Harding)
1a582db16021e696effeb6080d1197a23c620cf2 Remove redundant import (Tobin C. Harding)

Pull request description:

  The first 8 patches clear clippy warnings. Next we add a CI job to run clippy. Finally we add a `githooks` directory that includes running clippy, also adds a section to the README on how to use the githooks. This is identical to the text in the [open PR](rust-bitcoin/rust-bitcoin#1044) on `rust-bitcoin` that adds githooks _without_ yet adding clippy.

  **Note**: The new clippy CI job runs and is green :)

ACKs for top commit:
  Kixunil:
    ACK 65186e732ac229575afd83f5c11bfb794ebc3ca8
  apoelstra:
    ACK 65186e732ac229575afd83f5c11bfb794ebc3ca8

Tree-SHA512: f70a157896ce2a83af8cfc10f2fbacc8f68256ac96ef7dec4d190aa72324b568d2267418eb4fe99099aeda5486957c31070943d7c209973859b7b9290676ccd7
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.

5 participants