-
Notifications
You must be signed in to change notification settings - Fork 155
Clear some clippy warnings #367
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
Conversation
0663dae
to
c1c8ab0
Compare
@tcharding, would you prefer to get this in first? This seems like a big change. Almost of the open PRs are from you, let me know what order do you prefer to merge them to avoid least pain for you |
This one is painful to rebase so the sooner it goes in the better from my perspective. |
Add a clippy configuration file with the MSRV set to the current 1.41.1
Clippy emits: warning: this import is redundant As suggested, remove the redundant import.
Clippy emits: warning: redundant field names in struct initialization As suggested, use the field init shorthand.
Clippy emits: warning: unneeded unit return type As suggested, remove the unneeded unit return type
Clippy emits a bunch of warnings of the form warning: this expression borrows a reference (`&Self`) that is immediately dereferenced by the compiler As suggested, remove the unneeded explicit reference.
Clippy emits a bunch of warnings of the form: warning: unneeded `return` statement As suggested, remove the explicit return statement.
Clippy emits: warning: `ref` on an entire `let` pattern is discouraged, take a reference with `&` instead As suggested, use `&` instead of `ref`.
Clippy emits: warning: redundant slicing of the whole range As suggested, remove the redundant slicing of whole range.
Clippy emits: warning: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration) As suggested, remove explicit lifetimes and use `'_`,
Clippy emits: warning: use of `ok_or` followed by a function call As suggested, use `ok_or_else` with a closure.
Clippy emits: warning: you don't need to add `&` to all patterns Remove the reference on match arms.
Clippy emits: warning: you don't need to add `&` to both the expression and the patterns Remove reference from expression and patterns
Clippy emits: warning: useless conversion to the same type: `psbt::Error` As suggested, remove the call to `into`.
Clippy emits a bunch of warnings of form: warning: this `.into_iter()` call is equivalent to `.iter()` and will not consume the `slice` As suggested, use `iter` instead of `into_iter`.
Clippy emits a bunch of warnings of form: warning: redundant closure As suggested, remove the redundant closures and just pass in the function.
Clippy emits a couple of warnings of form: warning: length comparison to zero As suggested, use `is_empty` instead of manually comparing to zero.
Clippy emits: warning: manual `!RangeInclusive::contains` implementation As suggested, use contains instead of manual implementation.
We can derive these implementations. Found by clippy.
Clippy emits two warnings of the form: warning: redundant pattern matching, consider using ... As suggested use `is_none` and `is_ok` where appropriate.
Clippy emits: warning: useless conversion to the same type: `std::string::String` As suggested, remove the useless call to `String::from`
Clippy emits a couple of warnings of the form: warning: using `Option.and_then(|x| Some(y))`, which is more succinctly expressed as `map(|x| y)` As suggested, use `map` instead of `and_then`
This function consumes self so no need to clone it both times.
Now we have Rust 1.31 we can use `copied`. Clears clippy warning.
Clippy emits: warning: useless use of `format!` As suggested, use `to_string`.
Clippy emits: warning: calling `push_str()` using a single-character string literal As suggested, use `push` with character literal.
Clippy emits: error: this `if` has identical blocks Simplify the code by removing the duplicate blocks.
Clippy emits: warning: returning the result of a `let` binding from a block As suggested, return the block directly.
Clippy emits: warning: this pattern creates a reference to a reference As suggested remove the `ref` and use `v` directly.
Clippy emits a bunch of warnings of type: warning: using `clone` on type <elided> which implements the `Copy` trait As suggested, remove the redundant calls to clone.
Clippy emits: warning: use of `unwrap_or` followed by a function call As suggested use `unwrap_or_else`.
Clippy emits: warning: called `map(..).flatten()` on an `Iterator` As suggested, use `flat_map` instead.
Clippy emits: error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false The vars `k` and `thresh` are both of type `uszie` and can never be below zero, use `==` instead.
Clippy emits a few warnings of type: warning: used `sort` on primitive type `u32` As suggested, use `sort_unstable` on `u32` and `usize` primitives.
Clippy emits a bunch of warnings of type: warning: called `filter(..).next()` on an `Iterator`. This is more succinctly expressed by calling `.find(..)` instead As suggested, use `find` instead of chaining `filter` and `next`.
Clippy emits: error: the since field must contain a semver-compliant version As suggested, use a semvar-compliant version number.
I did not check that all the warnings of the type being fixed were fixed after rebase. Will do another round of clippy fixes after this one is merged. |
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 7da5327. Verified that there are only refactoring changes and no logical changes.
@@ -188,7 +188,7 @@ impl<Pk: MiniscriptKey> Policy<Pk> { | |||
// Witness is currently encoded as policy. Only accepts leaf fragment and | |||
// a normalized policy | |||
fn satisfy_constraint(self, witness: &Policy<Pk>, available: bool) -> Policy<Pk> { | |||
debug_assert!(self.clone().normalized() == self.clone()); | |||
debug_assert!(self.clone().normalized() == self); |
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.
Interesting, so self
is not moved here?
Because we are using self couple of lines below.
@@ -489,7 +489,7 @@ impl<Pk: MiniscriptKey> Policy<Pk> { | |||
/// which appear in the policy | |||
pub fn relative_timelocks(&self) -> Vec<u32> { | |||
let mut ret = self.real_relative_timelocks(); | |||
ret.sort(); | |||
ret.sort_unstable(); |
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.
Interesting. I learned something new today.
// THIS IS A BUG AND *WILL* PRODUCE WRONG SATISFACTIONS FOR UNCOMPRESSED KEYS | ||
// Partial sigs loses the compressed flag that is necessary | ||
// TODO: See https://github.com/rust-bitcoin/rust-bitcoin/pull/836 | ||
// The type checker will fail again after we update to 0.28 and this can be removed |
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.
Oops, this bug was fixed upstream, this comment should be removed.
Note to self: Instead of writing TODOs, make new issues.
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.
:)
// Create a pubkey hash and check if they are the same. | ||
let addr = bitcoin::Address::p2wpkh(&pk, bitcoin::Network::Bitcoin) | ||
.expect("Address corresponding to valid pubkey"); | ||
*script_pubkey == addr.script_pubkey() |
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.
I think this might motivate a Script::p2wpkh(bitcoin::PublicKey)
Make a start on clearing all the non-contentious clippy warnings.