Add lints to catch missing traits#364
Merged
apoelstra merged 4 commits intorust-bitcoin:masterfrom Jan 7, 2022
Merged
Conversation
Member
Author
|
This PR came about from discussion here. |
Clippy emits a few warnings: warning: unneeded `return` statement As suggested, remove the unneeded return statements.
Clippy emits: warning: useless use of `format!` As suggested, remove the useless call to `format!`.
3e9fadf to
dfe46b0
Compare
Rustc can warn us when we forget to add `Copy` and `Deubg` trait implementations to types. Add lint directives to enable warnings for missing `Copy` and `Debug` implementations. Use the newly emitted warnings to find types that do not implement our 'standard' traits. These 'standard' traits are defined as the set of attributes that it has been found beneficial to opportunistically add to all types, these are - Copy - Clone - Debug - PartialEq and Eq - PartialOrd and Ord - Hash
Currently we have an implementation of `Debug` (also used by `Display`) for `Signature` that first converts the sig to a `SerializedSignature` then prints it as hex. We would like to have an implementation of `Debug` for `SerializedSignature`, this cannot be derived because of the `data: [u8; field]`. We can manually implement `Debug` for `SerializedSignature` exactly as it is currently done for `Signature` and call this new implementation from `Signature::fmt()`. This code path is already tested in `lib.rs` in the test function `signature_display`.
dfe46b0 to
69f44d9
Compare
thomaseizinger
approved these changes
Jan 7, 2022
Contributor
thomaseizinger
left a comment
There was a problem hiding this comment.
ACK 69f44d9
I don't think we currently fail the build on warnings so this is mere a reminder for devs while working locally but that is already an improvement.
Member
|
The lints for |
Contributor
|
I am up for having a new point release: rust-bitcoin/rust-bitcoin@73f7e96#diff-5d6afe76bb8d0b9a17c480f8f357e3818d9e82dd9c53557428d274106bb6e3e7R61 |
Member
|
Another point release sounds good to me. |
chain-forgexcr45
added a commit
to chain-forgexcr45/rust-secp256k1
that referenced
this pull request
Sep 28, 2025
69f44d9301c54168e9eaaf046db3d478e6739173 Manually implement Debug for SerializedSignature (Tobin Harding) 26921a31b8a030fba1141aba9ee61201c21b2d6a Add lints to catch missing traits (Tobin Harding) 35556e22f20a47341a6f5c3c68416713fdf354c3 Remove useless call to format (Tobin Harding) 0ad414a9825f8a3e8d634ee3207e44538497b09b Remove unneeded return statements (Tobin Harding) Pull request description: We can use the linters to help us catch type definitions that are missing 'standard' derives. 'standard' is project defined to be - Copy - Clone - Debug - PartialEq and Eq - PartialOrd and Ord - Hash (I've assumed this to be true based on the code and an open [PR](rust-bitcoin/rust-bitcoin#587) in rust-bitcoin.) While neither Rustc nor Clippy can find all of these, Rustc can warn for missing `Copy` and `Debug` implementations and these warnings can assist us find types that may need additional derives. First two patches are trivial Clippy fixes in preparation for using the linter to improve type definitions crate wide. Patch 3 adds ``` #![warn(missing_copy_implementations)] #![warn(missing_debug_implementations)] ``` and fixes newly emitted warnings. ACKs for top commit: thomaseizinger: ACK 69f44d9301c54168e9eaaf046db3d478e6739173 apoelstra: ACK 69f44d9301c54168e9eaaf046db3d478e6739173 Tree-SHA512: 18f2c52d207f962ef7d6749a57a35e48eb18a18fac82d4df4ff3dce549b69661cb27f66c4cae516ae5477f5b919d9197f70a5c924955605c73f8545f430c3b42
william2332-limf
added a commit
to william2332-limf/rust-secp256k1
that referenced
this pull request
Oct 2, 2025
69f44d9301c54168e9eaaf046db3d478e6739173 Manually implement Debug for SerializedSignature (Tobin Harding) 26921a31b8a030fba1141aba9ee61201c21b2d6a Add lints to catch missing traits (Tobin Harding) 35556e22f20a47341a6f5c3c68416713fdf354c3 Remove useless call to format (Tobin Harding) 0ad414a9825f8a3e8d634ee3207e44538497b09b Remove unneeded return statements (Tobin Harding) Pull request description: We can use the linters to help us catch type definitions that are missing 'standard' derives. 'standard' is project defined to be - Copy - Clone - Debug - PartialEq and Eq - PartialOrd and Ord - Hash (I've assumed this to be true based on the code and an open [PR](rust-bitcoin/rust-bitcoin#587) in rust-bitcoin.) While neither Rustc nor Clippy can find all of these, Rustc can warn for missing `Copy` and `Debug` implementations and these warnings can assist us find types that may need additional derives. First two patches are trivial Clippy fixes in preparation for using the linter to improve type definitions crate wide. Patch 3 adds ``` #![warn(missing_copy_implementations)] #![warn(missing_debug_implementations)] ``` and fixes newly emitted warnings. ACKs for top commit: thomaseizinger: ACK 69f44d9301c54168e9eaaf046db3d478e6739173 apoelstra: ACK 69f44d9301c54168e9eaaf046db3d478e6739173 Tree-SHA512: 18f2c52d207f962ef7d6749a57a35e48eb18a18fac82d4df4ff3dce549b69661cb27f66c4cae516ae5477f5b919d9197f70a5c924955605c73f8545f430c3b42
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We can use the linters to help us catch type definitions that are missing 'standard' derives. 'standard' is project defined to be
(I've assumed this to be true based on the code and an open PR in rust-bitcoin.)
While neither Rustc nor Clippy can find all of these, Rustc can warn for missing
CopyandDebugimplementations and these warnings can assist us find types that may need additional derives.First two patches are trivial Clippy fixes in preparation for using the linter to improve type definitions crate wide.
Patch 3 adds
and fixes newly emitted warnings.