Fixing some clippy warnings (#1728)
* Fixing warnings * Fixing unnecessary ref * Removing unnecessary operation
This commit is contained in:
@@ -195,7 +195,7 @@ pub trait Populatable {
|
||||
/// If `d` is smaller, will leave some bytes untouched.
|
||||
fn copy_raw(&mut self, d: &[u8]) {
|
||||
use std::io::Write;
|
||||
self.as_slice_mut().write(&d).unwrap();
|
||||
self.as_slice_mut().write(d).unwrap();
|
||||
}
|
||||
|
||||
/// Copies the raw representation of an object `d` to `self`, overwriting as necessary.
|
||||
|
||||
@@ -273,7 +273,7 @@ pub mod ecdh {
|
||||
let publ = try!(key::PublicKey::from_slice(context, &pdata));
|
||||
// no way to create SecretKey from raw byte array.
|
||||
let sec: &key::SecretKey = unsafe { ::std::mem::transmute(secret) };
|
||||
let shared = ecdh::SharedSecret::new_raw(context, &publ, &sec);
|
||||
let shared = ecdh::SharedSecret::new_raw(context, &publ, sec);
|
||||
|
||||
let mut s = crypto::Secret::new();
|
||||
s.copy_from_slice(&shared[0..32]);
|
||||
|
||||
@@ -82,7 +82,7 @@ impl fmt::Display for UtilError {
|
||||
UtilError::BaseData(ref err) => f.write_fmt(format_args!("{}", err)),
|
||||
UtilError::Network(ref err) => f.write_fmt(format_args!("{}", err)),
|
||||
UtilError::Decoder(ref err) => f.write_fmt(format_args!("{}", err)),
|
||||
UtilError::SimpleString(ref msg) => f.write_str(&msg),
|
||||
UtilError::SimpleString(ref msg) => f.write_str(msg),
|
||||
UtilError::BadSize => f.write_str("Bad input size."),
|
||||
UtilError::Snappy(ref err) => f.write_fmt(format_args!("{}", err)),
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ impl EarlyMergeDB {
|
||||
// this is the first entry for this node in the journal.
|
||||
if backing.get(h).expect("Low-level database error. Some issue with your hard disk?").is_some() {
|
||||
// already in the backing DB. start counting, and remember it was already in.
|
||||
Self::set_already_in(batch, &h);
|
||||
Self::set_already_in(batch, h);
|
||||
refs.insert(h.clone(), RefInfo{queue_refs: 1, in_archive: true});
|
||||
if trace {
|
||||
trace!(target: "jdb.fine", " insert({}): New to queue, in DB: Recording and inserting into queue", h);
|
||||
|
||||
@@ -193,7 +193,7 @@ impl OverlayRecentDB {
|
||||
#[inline]
|
||||
fn to_short_key(key: &H256) -> H256 {
|
||||
let mut k = H256::new();
|
||||
&mut k[0..DB_PREFIX_LEN].copy_from_slice(&key[0..DB_PREFIX_LEN]);
|
||||
k[0..DB_PREFIX_LEN].copy_from_slice(&key[0..DB_PREFIX_LEN]);
|
||||
k
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,20 +19,16 @@
|
||||
#![cfg_attr(feature="dev", plugin(clippy))]
|
||||
|
||||
// Clippy settings
|
||||
// TODO [todr] not really sure
|
||||
// Most of the time much more readable
|
||||
#![cfg_attr(feature="dev", allow(needless_range_loop))]
|
||||
// Shorter than if-else
|
||||
#![cfg_attr(feature="dev", allow(match_bool))]
|
||||
// We use that to be more explicit about handled cases
|
||||
#![cfg_attr(feature="dev", allow(match_same_arms))]
|
||||
// Keeps consistency (all lines with `.clone()`) and helpful when changing ref to non-ref.
|
||||
// Keeps consistency (all lines with `.clone()`).
|
||||
#![cfg_attr(feature="dev", allow(clone_on_copy))]
|
||||
// In most cases it expresses function flow better
|
||||
#![cfg_attr(feature="dev", allow(if_not_else))]
|
||||
// TODO [todr] a lot of warnings to be fixed
|
||||
#![cfg_attr(feature="dev", allow(needless_borrow))]
|
||||
#![cfg_attr(feature="dev", allow(assign_op_pattern))]
|
||||
#![cfg_attr(feature="dev", allow(unnecessary_operation))]
|
||||
|
||||
|
||||
//! Ethcore-util library
|
||||
|
||||
@@ -355,7 +355,7 @@ impl EncryptedConnection {
|
||||
self.encoder.encrypt(&mut RefReadBuffer::new(&header), &mut RefWriteBuffer::new(&mut packet), false).expect("Invalid length or padding");
|
||||
EncryptedConnection::update_mac(&mut self.egress_mac, &mut self.mac_encoder, &packet[0..16]);
|
||||
self.egress_mac.clone().finalize(&mut packet[16..32]);
|
||||
self.encoder.encrypt(&mut RefReadBuffer::new(&payload), &mut RefWriteBuffer::new(&mut packet[32..(32 + len)]), padding == 0).expect("Invalid length or padding");
|
||||
self.encoder.encrypt(&mut RefReadBuffer::new(payload), &mut RefWriteBuffer::new(&mut packet[32..(32 + len)]), padding == 0).expect("Invalid length or padding");
|
||||
if padding != 0 {
|
||||
let pad = [0u8; 16];
|
||||
self.encoder.encrypt(&mut RefReadBuffer::new(&pad[0..padding]), &mut RefWriteBuffer::new(&mut packet[(32 + len)..(32 + len + padding)]), true).expect("Invalid length or padding");
|
||||
|
||||
@@ -167,7 +167,7 @@ impl Discovery {
|
||||
}
|
||||
|
||||
fn clear_ping(&mut self, id: &NodeId) {
|
||||
let mut bucket = self.node_buckets.get_mut(Discovery::distance(&self.id, &id) as usize).unwrap();
|
||||
let mut bucket = self.node_buckets.get_mut(Discovery::distance(&self.id, id) as usize).unwrap();
|
||||
if let Some(node) = bucket.nodes.iter_mut().find(|n| &n.address.id == id) {
|
||||
node.timeout = None;
|
||||
}
|
||||
@@ -438,7 +438,7 @@ impl Discovery {
|
||||
}
|
||||
let mut packets = Discovery::prepare_neighbours_packets(&nearest);
|
||||
for p in packets.drain(..) {
|
||||
self.send_packet(PACKET_NEIGHBOURS, &from, &p);
|
||||
self.send_packet(PACKET_NEIGHBOURS, from, &p);
|
||||
}
|
||||
trace!(target: "discovery", "Sent {} Neighbours to {:?}", nearest.len(), &from);
|
||||
Ok(None)
|
||||
|
||||
@@ -355,11 +355,11 @@ impl Host {
|
||||
let keys = if let Some(ref secret) = config.use_secret {
|
||||
KeyPair::from_secret(secret.clone()).unwrap()
|
||||
} else {
|
||||
config.config_path.clone().and_then(|ref p| load_key(&Path::new(&p)))
|
||||
config.config_path.clone().and_then(|ref p| load_key(Path::new(&p)))
|
||||
.map_or_else(|| {
|
||||
let key = KeyPair::create().unwrap();
|
||||
if let Some(path) = config.config_path.clone() {
|
||||
save_key(&Path::new(&path), &key.secret());
|
||||
save_key(Path::new(&path), key.secret());
|
||||
}
|
||||
key
|
||||
},
|
||||
@@ -1099,7 +1099,7 @@ fn save_key(path: &Path, key: &Secret) {
|
||||
return;
|
||||
}
|
||||
};
|
||||
if let Err(e) = restrict_permissions_owner(&path) {
|
||||
if let Err(e) = restrict_permissions_owner(path) {
|
||||
warn!(target: "network", "Failed to modify permissions of the file (chmod: {})", e);
|
||||
}
|
||||
if let Err(e) = file.write(&key.hex().into_bytes()) {
|
||||
|
||||
@@ -128,7 +128,7 @@ impl Session {
|
||||
nonce: &H256, stats: Arc<NetworkStats>, host: &HostInfo) -> Result<Session, UtilError>
|
||||
where Message: Send + Clone {
|
||||
let originated = id.is_some();
|
||||
let mut handshake = Handshake::new(token, id, socket, &nonce, stats).expect("Can't create handshake");
|
||||
let mut handshake = Handshake::new(token, id, socket, nonce, stats).expect("Can't create handshake");
|
||||
try!(handshake.start(io, host, originated));
|
||||
Ok(Session {
|
||||
state: State::Handshake(handshake),
|
||||
@@ -313,7 +313,7 @@ impl Session {
|
||||
self.connection().token()
|
||||
}
|
||||
|
||||
fn read_packet<Message>(&mut self, io: &IoContext<Message>, packet: Packet, host: &HostInfo) -> Result<SessionData, UtilError>
|
||||
fn read_packet<Message>(&mut self, io: &IoContext<Message>, packet: Packet, host: &HostInfo) -> Result<SessionData, UtilError>
|
||||
where Message: Send + Sync + Clone {
|
||||
if packet.data.len() < 2 {
|
||||
return Err(From::from(NetworkError::BadProtocol));
|
||||
@@ -381,7 +381,7 @@ impl Session {
|
||||
self.send(io, rlp)
|
||||
}
|
||||
|
||||
fn read_hello<Message>(&mut self, io: &IoContext<Message>, rlp: &UntrustedRlp, host: &HostInfo) -> Result<(), UtilError>
|
||||
fn read_hello<Message>(&mut self, io: &IoContext<Message>, rlp: &UntrustedRlp, host: &HostInfo) -> Result<(), UtilError>
|
||||
where Message: Send + Sync + Clone {
|
||||
let protocol = try!(rlp.val_at::<u32>(0));
|
||||
let client_version = try!(rlp.val_at::<String>(1));
|
||||
|
||||
@@ -168,7 +168,7 @@ impl OverlayDB {
|
||||
pub fn revert(&mut self) { self.overlay.clear(); }
|
||||
|
||||
/// Get the number of references that would be committed.
|
||||
pub fn commit_refs(&self, key: &H256) -> i32 { self.overlay.raw(&key).map_or(0, |&(_, refs)| refs) }
|
||||
pub fn commit_refs(&self, key: &H256) -> i32 { self.overlay.raw(key).map_or(0, |&(_, refs)| refs) }
|
||||
|
||||
/// Get the refs and value of the given key.
|
||||
fn payload(&self, key: &H256) -> Option<(Bytes, u32)> {
|
||||
|
||||
@@ -106,7 +106,7 @@ impl StandardMap {
|
||||
Alphabet::All => Self::random_bytes(self.min_key, self.journal_key, seed),
|
||||
Alphabet::Low => Self::random_word(low, self.min_key, self.journal_key, seed),
|
||||
Alphabet::Mid => Self::random_word(mid, self.min_key, self.journal_key, seed),
|
||||
Alphabet::Custom(ref a) => Self::random_word(&a, self.min_key, self.journal_key, seed),
|
||||
Alphabet::Custom(ref a) => Self::random_word(a, self.min_key, self.journal_key, seed),
|
||||
};
|
||||
let v = match self.value_mode {
|
||||
ValueMode::Mirror => k.clone(),
|
||||
|
||||
@@ -132,7 +132,7 @@ impl<'db> TrieDB<'db> {
|
||||
|
||||
/// Get the data of the root node.
|
||||
fn root_data(&self) -> &[u8] {
|
||||
self.db.get(&self.root).expect("Trie root not found!")
|
||||
self.db.get(self.root).expect("Trie root not found!")
|
||||
}
|
||||
|
||||
/// Get the root node as a `Node`.
|
||||
@@ -184,7 +184,7 @@ impl<'db> TrieDB<'db> {
|
||||
/// Return optional data for a key given as a `NibbleSlice`. Returns `None` if no data exists.
|
||||
fn do_lookup<'a, 'key>(&'a self, key: &NibbleSlice<'key>) -> Option<&'a [u8]> where 'a: 'key {
|
||||
let root_rlp = self.root_data();
|
||||
self.get_from_node(&root_rlp, key)
|
||||
self.get_from_node(root_rlp, key)
|
||||
}
|
||||
|
||||
/// Recursible function to retrieve the value given a `node` and a partial `key`. `None` if no
|
||||
@@ -340,7 +340,7 @@ impl<'db> Trie for TrieDB<'db> {
|
||||
Box::new(TrieDB::iter(self))
|
||||
}
|
||||
|
||||
fn root(&self) -> &H256 { &self.root }
|
||||
fn root(&self) -> &H256 { self.root }
|
||||
|
||||
fn contains(&self, key: &[u8]) -> bool {
|
||||
self.get(key).is_some()
|
||||
@@ -354,7 +354,7 @@ impl<'db> Trie for TrieDB<'db> {
|
||||
impl<'db> fmt::Debug for TrieDB<'db> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
try!(writeln!(f, "c={:?} [", self.hash_count));
|
||||
let root_rlp = self.db.get(&self.root).expect("Trie root not found!");
|
||||
let root_rlp = self.db.get(self.root).expect("Trie root not found!");
|
||||
try!(self.fmt_all(Node::decoded(root_rlp), f, 0));
|
||||
writeln!(f, "]")
|
||||
}
|
||||
@@ -373,7 +373,7 @@ fn iterator() {
|
||||
{
|
||||
let mut t = TrieDBMut::new(&mut memdb, &mut root);
|
||||
for x in &d {
|
||||
t.insert(&x, &x);
|
||||
t.insert(x, x);
|
||||
}
|
||||
}
|
||||
assert_eq!(d.iter().map(|i|i.to_vec()).collect::<Vec<_>>(), TrieDB::new(&memdb, &root).unwrap().iter().map(|x|x.0).collect::<Vec<_>>());
|
||||
|
||||
@@ -401,7 +401,7 @@ impl<'a> TrieDBMut<'a> {
|
||||
|
||||
/// Return optional data for a key given as a `NibbleSlice`. Returns `None` if no data exists.
|
||||
fn do_db_lookup<'x, 'key>(&'x self, hash: &H256, key: NibbleSlice<'key>) -> Option<&'x [u8]> where 'x: 'key {
|
||||
self.db.get(hash).and_then(|node_rlp| self.get_from_db_node(&node_rlp, key))
|
||||
self.db.get(hash).and_then(|node_rlp| self.get_from_db_node(node_rlp, key))
|
||||
}
|
||||
|
||||
/// Recursible function to retrieve the value given a `node` and a partial `key`. `None` if no
|
||||
@@ -868,7 +868,7 @@ impl<'a> TrieDBMut<'a> {
|
||||
impl<'a> TrieMut for TrieDBMut<'a> {
|
||||
fn root(&mut self) -> &H256 {
|
||||
self.commit();
|
||||
&self.root
|
||||
self.root
|
||||
}
|
||||
|
||||
fn is_empty(&self) -> bool {
|
||||
@@ -938,7 +938,7 @@ mod tests {
|
||||
for i in 0..v.len() {
|
||||
let key: &[u8]= &v[i].0;
|
||||
let val: &[u8] = &v[i].1;
|
||||
t.insert(&key, &val);
|
||||
t.insert(key, val);
|
||||
}
|
||||
t
|
||||
}
|
||||
@@ -946,7 +946,7 @@ mod tests {
|
||||
fn unpopulate_trie<'db>(t: &mut TrieDBMut<'db>, v: &[(Vec<u8>, Vec<u8>)]) {
|
||||
for i in v {
|
||||
let key: &[u8]= &i.0;
|
||||
t.remove(&key);
|
||||
t.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -213,7 +213,7 @@ fn hash256rlp(input: &[(Vec<u8>, Vec<u8>)], pre_len: usize, stream: &mut RlpStre
|
||||
.skip(1)
|
||||
// get minimum number of shared nibbles between first and each successive
|
||||
.fold(key.len(), | acc, &(ref k, _) | {
|
||||
cmp::min(key.shared_prefix_len(&k), acc)
|
||||
cmp::min(key.shared_prefix_len(k), acc)
|
||||
});
|
||||
|
||||
// if shared prefix is higher than current prefix append its
|
||||
|
||||
Reference in New Issue
Block a user