diff --git a/src/blockdata/blockchain.rs b/src/blockdata/blockchain.rs index 61595df9..cb82e939 100644 --- a/src/blockdata/blockchain.rs +++ b/src/blockdata/blockchain.rs @@ -264,7 +264,7 @@ pub struct RevBlockIter<'tree> { /// /// So to handle reorgs, you create a `RevStaleBlockIter` starting from the last /// known block, and play it until it runs out, rewinding every block except for -/// the last one. Since the UtxoSet `rewind` function sets its `last_hash()` to +/// the last one. Since the `UtxoSet` `rewind` function sets its `last_hash()` to /// the prevblockhash of the rewinded block (which will be on the main chain at /// the end of the iteration), you can then sync it up same as if you were doing /// a plain old fast-forward. @@ -327,7 +327,7 @@ impl<'tree> Iterator for RevStaleBlockIter<'tree> { } } -/// This function emulates the GetCompact(SetCompact(n)) in the satoshi code, +/// This function emulates the `GetCompact(SetCompact(n))` in the satoshi code, /// which drops the precision to something that can be encoded precisely in /// the nBits block header field. Savour the perversity. This is in Bitcoin /// consensus code. What. Gaah! diff --git a/src/blockdata/script.rs b/src/blockdata/script.rs index 8500aaa4..60228393 100644 --- a/src/blockdata/script.rs +++ b/src/blockdata/script.rs @@ -220,7 +220,7 @@ pub fn read_scriptint(v: &[u8]) -> Result { Ok(ret) } -/// This is like "read_scriptint then map 0 to false and everything +/// This is like "`read_scriptint` then map 0 to false and everything /// else as true", except that the overflow rules don't apply. #[inline] pub fn read_scriptbool(v: &[u8]) -> bool { diff --git a/src/blockdata/transaction.rs b/src/blockdata/transaction.rs index ee0fd208..f2a65b74 100644 --- a/src/blockdata/transaction.rs +++ b/src/blockdata/transaction.rs @@ -23,7 +23,7 @@ //! This module provides the structures and functions needed to support transactions. //! -use byteorder::{ByteOrder, LittleEndian, WriteBytesExt}; +use byteorder::{LittleEndian, WriteBytesExt}; use std::default::Default; use std::fmt; use serde; diff --git a/src/internal_macros.rs b/src/internal_macros.rs index 7466f5f7..03313ba6 100644 --- a/src/internal_macros.rs +++ b/src/internal_macros.rs @@ -137,6 +137,7 @@ macro_rules! impl_array_newtype { } } + #[cfg_attr(feature = "clippy", allow(expl_impl_clone_on_copy))] // we don't define the `struct`, we have to explicitly impl impl Clone for $thing { #[inline] fn clone(&self) -> $thing { diff --git a/src/lib.rs b/src/lib.rs index be7a83bf..509aca2b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,6 +30,10 @@ // Experimental features we need #![cfg_attr(all(test, feature = "unstable"), feature(test))] +// Clippy whitelist +#![cfg_attr(feature = "clippy", allow(needless_range_loop))] // suggests making a big mess of array newtypes +#![cfg_attr(feature = "clippy", allow(extend_from_slice))] // `extend_from_slice` only available since 1.6 + // Coding conventions #![deny(non_upper_case_globals)] #![deny(non_camel_case_types)] diff --git a/src/network/message.rs b/src/network/message.rs index 44da44e5..077ea2ea 100644 --- a/src/network/message.rs +++ b/src/network/message.rs @@ -79,8 +79,8 @@ pub enum SocketResponse { } #[derive(Clone, PartialEq, Eq, Debug)] -/// A Network message payload. Proper documentation is available on the Bitcoin -/// wiki https://en.bitcoin.it/wiki/Protocol_specification +/// A Network message payload. Proper documentation is available on at +/// [Bitcoin Wiki: Protocol Specification](https://en.bitcoin.it/wiki/Protocol_specification) pub enum NetworkMessage { /// `version` Version(message_network::VersionMessage), diff --git a/src/util/contracthash.rs b/src/util/contracthash.rs index 4c0bfacf..256c13b3 100644 --- a/src/util/contracthash.rs +++ b/src/util/contracthash.rs @@ -171,11 +171,11 @@ pub fn tweak_keys(secp: &Secp256k1, keys: &[PublicKey], contract: &[u8]) -> Resu let mut ret = Vec::with_capacity(keys.len()); for mut key in keys.iter().cloned() { let mut hmac_raw = [0; 32]; - let mut hmac = hmac::Hmac::new(sha2::Sha256::new(), &key.serialize_vec(&secp, true)); + let mut hmac = hmac::Hmac::new(sha2::Sha256::new(), &key.serialize_vec(secp, true)); hmac.input(contract); hmac.raw_result(&mut hmac_raw); - let hmac_sk = try!(SecretKey::from_slice(&secp, &hmac_raw).map_err(Error::BadTweak)); - try!(key.add_exp_assign(&secp, &hmac_sk).map_err(Error::Secp)); + let hmac_sk = try!(SecretKey::from_slice(secp, &hmac_raw).map_err(Error::BadTweak)); + try!(key.add_exp_assign(secp, &hmac_sk).map_err(Error::Secp)); ret.push(key); } Ok(ret) @@ -184,10 +184,10 @@ pub fn tweak_keys(secp: &Secp256k1, keys: &[PublicKey], contract: &[u8]) -> Resu /// Compute a tweak from some given data for the given public key pub fn compute_tweak(secp: &Secp256k1, pk: &PublicKey, contract: &[u8]) -> Result { let mut hmac_raw = [0; 32]; - let mut hmac = hmac::Hmac::new(sha2::Sha256::new(), &pk.serialize_vec(&secp, true)); + let mut hmac = hmac::Hmac::new(sha2::Sha256::new(), &pk.serialize_vec(secp, true)); hmac.input(contract); hmac.raw_result(&mut hmac_raw); - SecretKey::from_slice(&secp, &hmac_raw).map_err(Error::BadTweak) + SecretKey::from_slice(secp, &hmac_raw).map_err(Error::BadTweak) } /// Tweak a secret key using some arbitrary data (calls `compute_tweak` internally) diff --git a/src/util/misc.rs b/src/util/misc.rs index 61dd5ceb..5990404c 100644 --- a/src/util/misc.rs +++ b/src/util/misc.rs @@ -44,7 +44,7 @@ pub fn hex_bytes(s: &str) -> Result, Error> { // Check that there was no remainder match iter.remainder() { Some(_) => Err(Error::Detail( - format!("hexstring of odd length"), + "hexstring of odd length".to_owned(), Box::new(Error::ParseFailed) )), None => Ok(v) diff --git a/src/util/mod.rs b/src/util/mod.rs index 2cdc71c5..5b9a60c2 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -111,7 +111,7 @@ impl error::Error for Error { } } -/// Prepend the detail of an IoResult's error with some text to get poor man's backtracing +/// Prepend the detail of an `IoResult`'s error with some text to get poor man's backtracing pub fn propagate_err(s: String, res: Result) -> Result { res.map_err(|err| Error::Detail(s, Box::new(err))) } diff --git a/src/util/patricia_tree.rs b/src/util/patricia_tree.rs index 5be2e2be..6fb35c1b 100644 --- a/src/util/patricia_tree.rs +++ b/src/util/patricia_tree.rs @@ -375,26 +375,20 @@ impl Debug for PatriciaTree { } try!(writeln!(f, ": {:?}", tree.data)); // left gets no indentation - match tree.child_l { - Some(ref t) => { - for _ in 0..(depth + tree.skip_len as usize) { - try!(write!(f, "-")); - } - try!(write!(f, "0")); - try!(recurse(&**t, f, depth + tree.skip_len as usize + 1)); + if let Some(ref t) = tree.child_l { + for _ in 0..(depth + tree.skip_len as usize) { + try!(write!(f, "-")); } - None => { } + try!(write!(f, "0")); + try!(recurse(&**t, f, depth + tree.skip_len as usize + 1)); } // right one gets indentation - match tree.child_r { - Some(ref t) => { - for _ in 0..(depth + tree.skip_len as usize) { - try!(write!(f, "_")); - } - try!(write!(f, "1")); - try!(recurse(&**t, f, depth + tree.skip_len as usize + 1)); + if let Some(ref t) = tree.child_r { + for _ in 0..(depth + tree.skip_len as usize) { + try!(write!(f, "_")); } - None => { } + try!(write!(f, "1")); + try!(recurse(&**t, f, depth + tree.skip_len as usize + 1)); } Ok(()) }