From bd74cc2fa9b3aa021d263affa0a7a9cb085dc961 Mon Sep 17 00:00:00 2001 From: Andreas Fackler Date: Wed, 9 Jan 2019 11:56:40 +0100 Subject: [PATCH] Use Rust 2018 idioms consistently. Apply `cargo fix --edition-idioms`. --- examples/network/commst.rs | 2 +- src/binary_agreement/binary_agreement.rs | 2 +- src/binary_agreement/bool_multimap.rs | 2 +- src/broadcast/broadcast.rs | 2 +- src/broadcast/message.rs | 6 ++-- .../dynamic_honey_badger.rs | 2 +- src/honey_badger/epoch_state.rs | 2 +- src/lib.rs | 2 +- src/subset/subset.rs | 4 +-- src/sync_key_gen.rs | 4 +-- src/threshold_sign.rs | 2 +- src/util.rs | 2 +- tests/binary_agreement_mitm.rs | 6 ++-- tests/net/adversary.rs | 28 +++++++++---------- tests/net/err.rs | 6 ++-- tests/net/mod.rs | 6 ++-- tests/network/mod.rs | 2 +- 17 files changed, 40 insertions(+), 40 deletions(-) diff --git a/examples/network/commst.rs b/examples/network/commst.rs index 16cc19a..e7d6702 100644 --- a/examples/network/commst.rs +++ b/examples/network/commst.rs @@ -14,7 +14,7 @@ use hbbft::SourcedMessage; /// A communication task connects a remote node to the thread that manages the /// consensus algorithm. -pub struct CommsTask<'a, M: 'a> { +pub struct CommsTask<'a, M> { /// The transmit side of the multiple producer channel from comms threads. tx: &'a Sender>, /// The receive side of the channel to the comms thread. diff --git a/src/binary_agreement/binary_agreement.rs b/src/binary_agreement/binary_agreement.rs index d4168f4..86e564e 100644 --- a/src/binary_agreement/binary_agreement.rs +++ b/src/binary_agreement/binary_agreement.rs @@ -522,7 +522,7 @@ impl BinaryAgreement { } impl fmt::Display for BinaryAgreement { - fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> result::Result<(), fmt::Error> { write!( f, "{:?} BA {} epoch {} ({})", diff --git a/src/binary_agreement/bool_multimap.rs b/src/binary_agreement/bool_multimap.rs index 94165cb..cdced21 100644 --- a/src/binary_agreement/bool_multimap.rs +++ b/src/binary_agreement/bool_multimap.rs @@ -34,7 +34,7 @@ impl<'a, N: Ord> IntoIterator for &'a BoolMultimap { } } -pub struct Iter<'a, N: 'a> { +pub struct Iter<'a, N> { key: bool, set_iter: btree_set::Iter<'a, N>, map: &'a BoolMultimap, diff --git a/src/broadcast/broadcast.rs b/src/broadcast/broadcast.rs index 3ed9c14..e57d250 100644 --- a/src/broadcast/broadcast.rs +++ b/src/broadcast/broadcast.rs @@ -410,7 +410,7 @@ impl Broadcast { } impl fmt::Display for Broadcast { - fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> result::Result<(), fmt::Error> { write!(f, "{:?} Broadcast({:?})", self.our_id(), self.proposer_id) } } diff --git a/src/broadcast/message.rs b/src/broadcast/message.rs index 2c43052..40e67ae 100644 --- a/src/broadcast/message.rs +++ b/src/broadcast/message.rs @@ -43,7 +43,7 @@ impl Distribution for Standard { } impl Debug for Message { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { Message::Value(ref v) => f.debug_tuple("Value").field(&HexProof(v)).finish(), Message::Echo(ref v) => f.debug_tuple("Echo").field(&HexProof(v)).finish(), @@ -52,10 +52,10 @@ impl Debug for Message { } } /// Wrapper for a `Proof`, to print the bytes as a shortened hexadecimal number. -pub struct HexProof<'a, T: 'a>(pub &'a Proof); +pub struct HexProof<'a, T>(pub &'a Proof); impl<'a, T: AsRef<[u8]>> fmt::Debug for HexProof<'a, T> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, "Proof {{ #{}, root_hash: {:0.10}, value: {:0.10}, .. }}", diff --git a/src/dynamic_honey_badger/dynamic_honey_badger.rs b/src/dynamic_honey_badger/dynamic_honey_badger.rs index 4dbd64d..cdc87ff 100644 --- a/src/dynamic_honey_badger/dynamic_honey_badger.rs +++ b/src/dynamic_honey_badger/dynamic_honey_badger.rs @@ -536,7 +536,7 @@ where C: Contribution + Serialize + DeserializeOwned, N: NodeIdT + Serialize + DeserializeOwned, { - fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> result::Result<(), fmt::Error> { write!(f, "{:?} DHB(era: {})", self.our_id(), self.era) } } diff --git a/src/honey_badger/epoch_state.rs b/src/honey_badger/epoch_state.rs index 85d11d1..d6ffbef 100644 --- a/src/honey_badger/epoch_state.rs +++ b/src/honey_badger/epoch_state.rs @@ -404,7 +404,7 @@ struct EpochId { } impl Display for EpochId { - fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> result::Result<(), fmt::Error> { write!(f, "{}/{}", self.hb_id, self.epoch) } } diff --git a/src/lib.rs b/src/lib.rs index ff4539f..668ae30 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -119,7 +119,7 @@ #![allow(clippy::module_inception, clippy::new_ret_no_self)] #![warn(missing_docs)] -pub extern crate threshold_crypto as crypto; +pub use threshold_crypto as crypto; mod fault_log; mod messaging; diff --git a/src/subset/subset.rs b/src/subset/subset.rs index e2d0293..e85b803 100644 --- a/src/subset/subset.rs +++ b/src/subset/subset.rs @@ -170,7 +170,7 @@ impl Subset { } impl fmt::Display for Subset { - fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> result::Result<(), fmt::Error> { write!(f, "{:?} Subset({})", self.our_id(), self.session_id) } } @@ -185,7 +185,7 @@ pub struct BaSessionId { } impl fmt::Display for BaSessionId { - fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> result::Result<(), fmt::Error> { write!( f, "subset {}, proposer #{}", diff --git a/src/sync_key_gen.rs b/src/sync_key_gen.rs index e3257cd..ac98f6a 100644 --- a/src/sync_key_gen.rs +++ b/src/sync_key_gen.rs @@ -225,7 +225,7 @@ impl From for Error { pub struct Part(BivarCommitment, Vec); impl Debug for Part { - fn fmt(&self, f: &mut Formatter) -> fmt::Result { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { f.debug_tuple("Part") .field(&format!("", self.0.degree())) .field(&format!("<{} rows>", self.1.len())) @@ -242,7 +242,7 @@ impl Debug for Part { pub struct Ack(u64, Vec); impl Debug for Ack { - fn fmt(&self, f: &mut Formatter) -> fmt::Result { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { f.debug_tuple("Ack") .field(&self.0) .field(&format!("<{} values>", self.1.len())) diff --git a/src/threshold_sign.rs b/src/threshold_sign.rs index 19b3861..3422238 100644 --- a/src/threshold_sign.rs +++ b/src/threshold_sign.rs @@ -271,7 +271,7 @@ impl ThresholdSign { } impl fmt::Display for ThresholdSign { - fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> result::Result<(), fmt::Error> { write!(f, "{:?} TS({:?})", self.our_id(), self.doc_hash) } } diff --git a/src/util.rs b/src/util.rs index 6bd155b..db1fce9 100644 --- a/src/util.rs +++ b/src/util.rs @@ -8,7 +8,7 @@ use std::fmt; use hex_fmt::HexFmt; /// Prints a byte slice as shortened hexadecimal in debug output. -pub fn fmt_hex>(bytes: T, f: &mut fmt::Formatter) -> fmt::Result { +pub fn fmt_hex>(bytes: T, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{:10}", HexFmt(bytes)) } diff --git a/tests/binary_agreement_mitm.rs b/tests/binary_agreement_mitm.rs index ff8e72f..046c641 100644 --- a/tests/binary_agreement_mitm.rs +++ b/tests/binary_agreement_mitm.rs @@ -295,7 +295,7 @@ impl AbaCommonCoinAdversary { } } - fn inject_stage_messages(&mut self, net: &mut NetMutHandle) { + fn inject_stage_messages(&mut self, net: &mut NetMutHandle<'_, Algo, Self>) { if self.sent_stage_messages { return; } @@ -378,7 +378,7 @@ impl AbaCommonCoinAdversary { } impl Adversary for AbaCommonCoinAdversary { - fn pre_crank(&mut self, mut net: NetMutHandle, rng: &mut R) { + fn pre_crank(&mut self, mut net: NetMutHandle<'_, Algo, Self>, rng: &mut R) { self.inject_stage_messages(&mut net); net.sort_messages_by(|a, b| { a.payload() @@ -414,7 +414,7 @@ impl Adversary for AbaCommonCoinAdversary { fn tamper( &mut self, - _: NetMutHandle, + _: NetMutHandle<'_, Algo, Self>, msg: NetMessage, _rng: &mut R, ) -> Result, CrankError> { diff --git a/tests/net/adversary.rs b/tests/net/adversary.rs index 79c6fdb..ce6c1e4 100644 --- a/tests/net/adversary.rs +++ b/tests/net/adversary.rs @@ -46,7 +46,7 @@ use crate::net::{CrankError, NetMessage, Node, VirtualNet}; /// /// Allows querying public information of the network or getting immutable handles to any node. #[derive(Debug)] -pub struct NetHandle<'a, D: 'a, A>(&'a VirtualNet) +pub struct NetHandle<'a, D, A>(&'a VirtualNet) where D: ConsensusProtocol, D::Message: Clone, @@ -62,7 +62,7 @@ where { /// Returns a node handle iterator over all nodes in the network. #[inline] - pub fn nodes(&self) -> impl Iterator> { + pub fn nodes(&self) -> impl Iterator> { self.0.nodes().map(NodeHandle::new) } @@ -79,7 +79,7 @@ where /// Returns a node handle iterator over all correct nodes in the network. #[inline] - pub fn correct_nodes(&self) -> impl Iterator> { + pub fn correct_nodes(&self) -> impl Iterator> { self.0.correct_nodes().map(NodeHandle::new) } @@ -91,7 +91,7 @@ where /// Returns a handle to a specific node handle. #[inline] - pub fn get(&self, id: D::NodeId) -> Option> { + pub fn get(&self, id: D::NodeId) -> Option> { self.0.get(id).map(NodeHandle::new) } } @@ -112,7 +112,7 @@ pub enum QueuePosition { /// Allows reordering of messages, injecting new ones into the network queue and getting mutable /// handles to nodes. #[derive(Debug)] -pub struct NetMutHandle<'a, D: 'a, A>(&'a mut VirtualNet) +pub struct NetMutHandle<'a, D, A>(&'a mut VirtualNet) where D: ConsensusProtocol, D::Message: Clone, @@ -133,7 +133,7 @@ where /// Returns a mutable node handle iterator over all nodes in the network. #[inline] - pub fn nodes_mut(&mut self) -> impl Iterator> { + pub fn nodes_mut(&mut self) -> impl Iterator> { self.0.nodes_mut().map(NodeMutHandle::new) } @@ -148,7 +148,7 @@ where /// Returns a mutable node handle iterator over all nodes in the network. #[inline] - pub fn correct_nodes_mut(&mut self) -> impl Iterator> { + pub fn correct_nodes_mut(&mut self) -> impl Iterator> { self.0.correct_nodes_mut().map(NodeMutHandle::new) } @@ -233,14 +233,14 @@ where D::Output: Clone, { #[inline] - fn from(n: NetMutHandle) -> NetHandle { + fn from(n: NetMutHandle<'_, D, A>) -> NetHandle<'_, D, A> { NetHandle(n.0) } } /// Immutable node handle. #[derive(Debug)] -pub struct NodeHandle<'a, D: 'a>(&'a Node) +pub struct NodeHandle<'a, D>(&'a Node) where D: ConsensusProtocol; @@ -284,7 +284,7 @@ where /// Mutable node handle. #[derive(Debug)] -pub struct NodeMutHandle<'a, D: 'a>(&'a mut Node) +pub struct NodeMutHandle<'a, D>(&'a mut Node) where D: ConsensusProtocol; @@ -334,7 +334,7 @@ where /// /// The default implementation does not alter the passed network in any way. #[inline] - fn pre_crank(&mut self, _net: NetMutHandle, _rng: &mut R) {} + fn pre_crank(&mut self, _net: NetMutHandle<'_, D, Self>, _rng: &mut R) {} /// Tamper with a faulty node's operation. /// @@ -352,7 +352,7 @@ where #[inline] fn tamper( &mut self, - mut net: NetMutHandle, + mut net: NetMutHandle<'_, D, Self>, msg: NetMessage, rng: &mut R, ) -> Result, CrankError> { @@ -407,7 +407,7 @@ where D::Output: Clone, { #[inline] - fn pre_crank(&mut self, mut net: NetMutHandle, _rng: &mut R) { + fn pre_crank(&mut self, mut net: NetMutHandle<'_, D, Self>, _rng: &mut R) { // Message are sorted by NodeID on each step. net.sort_messages_by(|a, b| a.to.cmp(&b.to)) } @@ -434,7 +434,7 @@ where D::Output: Clone, { #[inline] - fn pre_crank(&mut self, mut net: NetMutHandle, rng: &mut R) { + fn pre_crank(&mut self, mut net: NetMutHandle<'_, D, Self>, rng: &mut R) { let l = net.0.messages_len(); if l > 0 { net.swap_messages(0, rng.gen_range(0, l)); diff --git a/tests/net/err.rs b/tests/net/err.rs index 418c509..fea47ea 100644 --- a/tests/net/err.rs +++ b/tests/net/err.rs @@ -66,7 +66,7 @@ impl Display for CrankError where D: ConsensusProtocol, { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { CrankError::HandleInput(err) => { write!(f, "The algorithm could not process input: {:?}", err) @@ -122,7 +122,7 @@ impl Debug for CrankError where D: ConsensusProtocol, { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { CrankError::HandleInput(err) => { f.debug_struct("HandleInput").field("err", err).finish() @@ -170,7 +170,7 @@ impl failure::Fail for CrankError where D: ConsensusProtocol + 'static, { - fn cause(&self) -> Option<&failure::Fail> { + fn cause(&self) -> Option<&dyn failure::Fail> { match self { CrankError::HandleInput(err) | CrankError::HandleInputAll(err) => Some(err), CrankError::HandleMessage { err, .. } => Some(err), diff --git a/tests/net/mod.rs b/tests/net/mod.rs index 03ab2c3..2a3978a 100644 --- a/tests/net/mod.rs +++ b/tests/net/mod.rs @@ -82,7 +82,7 @@ impl fmt::Debug for Node where D: ConsensusProtocol, { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Node") .field("algorithm", &"yes") .field("is_faulty", &self.is_faulty) @@ -317,7 +317,7 @@ where /// Number of faulty nodes in the network. num_faulty: usize, /// Dist-algorithm constructor function. - cons: Option) -> (D, CpStep)>>, + cons: Option) -> (D, CpStep)>>, /// Network adversary. adversary: Option, /// Trace-enabling flag. `None` means use environment. @@ -338,7 +338,7 @@ where D: ConsensusProtocol, A: fmt::Debug, { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("NetBuilder") .field("node_ids", &()) .field("num_faulty", &self.num_faulty) diff --git a/tests/network/mod.rs b/tests/network/mod.rs index 38bbe67..f21a245 100644 --- a/tests/network/mod.rs +++ b/tests/network/mod.rs @@ -142,7 +142,7 @@ pub struct MessageWithSender { // The Debug implementation cannot be derived automatically, possibly due to a compiler bug. For // this reason, it is implemented manually here. impl fmt::Debug for MessageWithSender { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, "MessageWithSender {{ sender: {:?}, tm: {:?} }}",