Fix public API clippy warnings#1161
Merged
apoelstra merged 3 commits intorust-bitcoin:masterfrom Aug 2, 2022
Merged
Conversation
Turns out by default clippy does not lint certain parts of the public API. Specifically, by setting avoid-breaking-exported-api = false we can get clippy to lint the public API for various things including `wrong_self_convention`. Clippy emits: warning: methods with the following characteristics: (`to_*` and `self` type is `Copy`) usually take `self` by value As suggested, take `self` by value for methods named `to_*`.
Clippy gives a warning about `wrong_self_convention` because we consume self in a method called `is_*`. We have to consume self because the object has a generic `E` (error type) that does not implement `Copy`.
Error variants should not end with the same identifier as the enum, i.e., they should not stutter. Found by clippy after setting: avoid-breaking-exported-api = false
cddfb63 to
5cef2f1
Compare
Member
Author
|
Once I actually ran the tests (bad Tobin), I was sad to see that with all these pubic API changes this PR only includes changes to one unit test and one rustdoc example. I think we need more thorough testing of our public API if we are going to achieve stability. |
Kixunil
approved these changes
Aug 1, 2022
| /// } | ||
| /// ``` | ||
| #[allow(clippy::wrong_self_convention)] // E is not Copy so we consume self. | ||
| pub fn is_sighash_single_bug(self) -> Result<bool, E> { |
Collaborator
There was a problem hiding this comment.
I knew this was ugly when I saw it the first time. Sadly, I have no idea how to improve the name.
Member
Author
There was a problem hiding this comment.
Ha that's funny, I thought the same myself on both accounts.
apoelstra
approved these changes
Aug 2, 2022
3 tasks
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.
Turns out by default clippy does not lint certain parts of the public API.
Specifically, by setting
avoid-breaking-exported-api = falsewe can get clippy to lint the public API for various things includingwrong_self_convention.This means the saga of to/into/as continues ... we have used the wrong from for many of our
to_*methods, they should consmeself. Patch 1 fixes them. Patch 2 adds anallow. Patch 3 fixes a few error enum variant identifiers (removesErrorsuffix).