-
Notifications
You must be signed in to change notification settings - Fork 267
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
Add lints to catch missing traits #364
Conversation
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 69f44d9
lol @ deriving traits on types that are impossible to instantiate, but if it lets us run these lints cleanly it's good by me.
The lints for |
I am up for having a new point release: rust-bitcoin/rust-bitcoin@73f7e96#diff-5d6afe76bb8d0b9a17c480f8f357e3818d9e82dd9c53557428d274106bb6e3e7R61 |
Another point release sounds good to me. |
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
Copy
andDebug
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
and fixes newly emitted warnings.