cargo-clippy cleanups

This commit is contained in:
Andrew Poelstra 2016-06-21 14:35:27 +00:00
parent 1dbd1c28dc
commit 1e47019221
10 changed files with 28 additions and 29 deletions

View File

@ -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!

View File

@ -220,7 +220,7 @@ pub fn read_scriptint(v: &[u8]) -> Result<i64, Error> {
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 {

View File

@ -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;

View File

@ -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 {

View File

@ -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)]

View File

@ -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),

View File

@ -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<SecretKey, Error> {
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)

View File

@ -44,7 +44,7 @@ pub fn hex_bytes(s: &str) -> Result<Vec<u8>, 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)

View File

@ -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<T>(s: String, res: Result<T, Error>) -> Result<T, Error> {
res.map_err(|err| Error::Detail(s, Box::new(err)))
}

View File

@ -375,26 +375,20 @@ impl<K: Copy + BitArray, V: Debug> Debug for PatriciaTree<K, V> {
}
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(())
}