Skip to content

Commit

Permalink
Some clippy fixes
Browse files Browse the repository at this point in the history
.. while reading around
  • Loading branch information
huitseeker committed Apr 17, 2021
1 parent 210c003 commit 1e304d9
Show file tree
Hide file tree
Showing 42 changed files with 223 additions and 254 deletions.
5 changes: 1 addition & 4 deletions blockchain/blocks/src/election_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,7 @@ pub mod json {
vrfproof,
win_count,
} = Deserialize::deserialize(deserializer)?;
Ok(ElectionProof {
vrfproof,
win_count,
})
Ok(ElectionProof { win_count, vrfproof })
}

pub mod opt {
Expand Down
2 changes: 1 addition & 1 deletion blockchain/chain/src/store/chain_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ mod tests {
let cs = ChainStore::new(Arc::new(db));
let gen_block = BlockHeader::builder()
.epoch(1)
.weight((2 as u32).into())
.weight(2_u32.into())
.messages(cid::new_from_cbor(&[], Identity))
.message_receipts(cid::new_from_cbor(&[], Identity))
.state_root(cid::new_from_cbor(&[], Identity))
Expand Down
2 changes: 1 addition & 1 deletion blockchain/chain_sync/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ mod tests {
Sender<NetworkEvent>,
Receiver<NetworkMessage>,
) {
let chain_store = Arc::new(ChainStore::new(db.clone()));
let chain_store = Arc::new(ChainStore::new(db));
let test_provider = TestApi::default();
let (tx, _rx) = bounded(10);
let mpool = task::block_on(MessagePool::new(
Expand Down
8 changes: 4 additions & 4 deletions blockchain/chain_sync/src/sync/peer_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::time::Duration;
fn peer_manager_update() {
let db = Arc::new(MemoryDB::default());

let chain_store = Arc::new(ChainStore::new(db.clone()));
let chain_store = Arc::new(ChainStore::new(db));
let (tx, _rx) = bounded(10);
let mpool = task::block_on(MessagePool::new(
TestApi::default(),
Expand Down Expand Up @@ -61,17 +61,17 @@ fn peer_manager_update() {
)
.unwrap();

let peer_manager = Arc::clone(&cs.network.peer_manager.clone());
let peer_manager = Arc::clone(&cs.network.peer_manager);

let (worker_tx, worker_rx) = bounded(10);
task::spawn(async {
cs.start(worker_tx, worker_rx).await;
});

let source = PeerId::random();
let source_clone = source.clone();
let source_clone = source;

let gen_cloned = genesis_ts.clone();
let gen_cloned = genesis_ts;
task::block_on(async {
event_sender
.send(NetworkEvent::HelloRequest {
Expand Down
2 changes: 1 addition & 1 deletion blockchain/chain_sync/src/sync_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@ mod tests {
task::block_on(async move {
sw.network
.peer_manager()
.update_peer_head(source.clone(), head.clone())
.update_peer_head(source, head.clone())
.await;
assert_eq!(sw.network.peer_manager().len().await, 1);
// make chain_exchange request
Expand Down
2 changes: 1 addition & 1 deletion blockchain/chain_sync/src/sync_worker/full_sync_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async fn space_race_full_sync() {
let network = SyncNetworkContext::new(network_send, Arc::new(peer_manager), db);

let provider_db = Arc::new(MemoryDB::default());
let cids: Vec<Cid> = load_car(provider_db.as_ref(), EXPORT_SR_40.as_ref())
let cids: Vec<Cid> = load_car(provider_db.as_ref(), EXPORT_SR_40)
.await
.unwrap();
let prov_cs = ChainStore::new(provider_db);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async fn validate_specific_block() {

let db = Arc::new(MemoryDB::default());

let cids = load_car(db.as_ref(), EXPORT_SR_40.as_ref()).await.unwrap();
let cids = load_car(db.as_ref(), EXPORT_SR_40).await.unwrap();

let chain_store = Arc::new(ChainStore::new(db.clone()));
let state_manager = Arc::new(StateManager::new(chain_store.clone()));
Expand Down
6 changes: 3 additions & 3 deletions blockchain/message_pool/src/msgpool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,8 @@ pub mod tests {
gas_price: u64,
) -> SignedMessage {
let umsg: UnsignedMessage = UnsignedMessage::builder()
.to(to.clone())
.from(from.clone())
.to(*to)
.from(*from)
.sequence(sequence)
.gas_limit(gas_limit)
.gas_fee_cap((gas_price + 100).into())
Expand Down Expand Up @@ -860,7 +860,7 @@ pub mod tests {
let mut smsg_vec = Vec::new();
tma.write()
.await
.set_state_balance_raw(&a1, BigInt::from(1_000_000_000_000_000_000 as u64));
.set_state_balance_raw(&a1, BigInt::from(1_000_000_000_000_000_000_u64));
for i in 0..10 {
let msg = if i != 5 {
create_smsg(&a2, &a1, wallet.borrow_mut(), i, gas_limit, 1 + i)
Expand Down
39 changes: 19 additions & 20 deletions blockchain/state_manager/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,30 @@ where
.ok_or_else(|| Error::State("Power actor address could not be resolved".to_string()))?;
let mas = miner::State::load(self.blockstore(), &actor)?;

let proving_sectors = if nv < NetworkVersion::V7 {
let proving_sectors = {
let mut proving_sectors = BitField::new();
mas.for_each_deadline(store, |_, deadline| {
let mut fault_sectors = BitField::new();
deadline.for_each(store, |_, partition: miner::Partition| {
proving_sectors |= &partition.all_sectors();
fault_sectors |= &partition.faulty_sectors();
Ok(())
})?;

proving_sectors -= &fault_sectors;
Ok(())
})?;
if nv < NetworkVersion::V7 {
mas.for_each_deadline(store, |_, deadline| {
let mut fault_sectors = BitField::new();
deadline.for_each(store, |_, partition: miner::Partition| {
proving_sectors |= &partition.all_sectors();
fault_sectors |= &partition.faulty_sectors();
Ok(())
})?;

proving_sectors
} else {
let mut proving_sectors = BitField::new();
mas.for_each_deadline(store, |_, deadline| {
deadline.for_each(store, |_, partition: miner::Partition| {
proving_sectors |= &partition.active_sectors();
proving_sectors -= &fault_sectors;
Ok(())
})?;
Ok(())
})?;

} else {
mas.for_each_deadline(store, |_, deadline| {
deadline.for_each(store, |_, partition: miner::Partition| {
proving_sectors |= &partition.active_sectors();
Ok(())
})?;
Ok(())
})?;
}
proving_sectors
};

Expand Down
2 changes: 1 addition & 1 deletion encoding/src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ mod tests {

#[test]
fn array_symmetric_serialization() {
let vec: Vec<u8> = (0..32).map(|x| x).collect::<Vec<u8>>();
let vec: Vec<u8> = (0..32).collect::<Vec<u8>>();
let slice_bz = to_vec(&BytesSer(&vec)).unwrap();
let Byte32De(arr) = from_slice(&slice_bz).unwrap();
// Check decoded array against slice
Expand Down
1 change: 1 addition & 0 deletions ipld/amt/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ where
/// Flushes cache for node, replacing any cached values with a Cid variant
pub(super) fn flush<DB: BlockStore>(&mut self, bs: &DB) -> Result<(), Error> {
if let Node::Link { links } = self {
#[allow(clippy::manual_flatten)]
for link in links.iter_mut() {
// links should only be flushed if the bitmap is set.
if let Some(Link::Dirty(n)) = link {
Expand Down
10 changes: 5 additions & 5 deletions ipld/blockstore/src/buffered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,16 +299,16 @@ mod tests {
)
.unwrap();
let map = ipld!({
"array": Link(arr_cid.clone()),
"sealed": Link(sealed_comm_cid.clone()),
"unsealed": Link(unsealed_comm_cid.clone()),
"identity": Link(identity_cid.clone()),
"array": Link(arr_cid),
"sealed": Link(sealed_comm_cid),
"unsealed": Link(unsealed_comm_cid),
"identity": Link(identity_cid),
"value": str_val,
});
let map_cid = buf_store.put(&map, Code::Blake2b256).unwrap();

let root_cid = buf_store
.put(&(map_cid.clone(), 1u8), Code::Blake2b256)
.put(&(map_cid, 1u8), Code::Blake2b256)
.unwrap();

// Make sure a block not connected to the root does not get written
Expand Down
2 changes: 1 addition & 1 deletion ipld/cid/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl Cid {
}

/// Returns the encoded bytes of the `Cid`.
pub fn to_bytes(&self) -> Vec<u8> {
pub fn to_bytes(self) -> Vec<u8> {
self.0.to_bytes()
}
}
Expand Down
2 changes: 1 addition & 1 deletion ipld/cid/tests/base_cid_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ fn test_hash() {
};
let mut map = HashMap::new();
let cid = forest_cid::new_from_prefix(&prefix, &data).unwrap();
map.insert(cid.clone(), data.clone());
map.insert(cid, data.clone());
assert_eq!(&data, map.get(&cid).unwrap());
}

Expand Down
2 changes: 1 addition & 1 deletion ipld/hamt/tests/hamt_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ fn clean_child_ordering() {
let mut h: Hamt<_, _> = Hamt::new_with_bit_width(&store, 5);

for i in 100..195 {
h.set(make_key(i), dummy_value.clone()).unwrap();
h.set(make_key(i), dummy_value).unwrap();
}

let root = h.flush().unwrap();
Expand Down
10 changes: 5 additions & 5 deletions ipld/tests/cbor_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn encode_new_type() {
let name = "Test".to_string();
let t_struct = TestStruct {
name: name.clone(),
details: details.clone(),
details,
};
let struct_encoded = to_vec(&t_struct).unwrap();

Expand All @@ -43,22 +43,22 @@ fn cid_conversions_ipld() {
let cid = cid::new_from_cbor(&[1, 2, 3], Blake2b256);
let m_s = TestStruct {
name: "s".to_owned(),
details: cid.clone(),
details: cid,
};
assert_eq!(
to_ipld(&m_s).unwrap(),
ipld!({"name": "s", "details": Link(cid.clone()) })
ipld!({"name": "s", "details": Link(cid) })
);
let serialized = to_vec(&cid).unwrap();
let ipld = ipld!(Link(cid.clone()));
let ipld = ipld!(Link(cid));
let ipld2 = to_ipld(&cid).unwrap();
assert_eq!(ipld, ipld2);
assert_eq!(to_vec(&ipld).unwrap(), serialized);
assert_eq!(to_ipld(&cid).unwrap(), Ipld::Link(cid));

// Test with identity hash (different length prefix for cbor)
let cid = cid::new_from_cbor(&[1, 2], Identity);
let ipld = ipld!(Link(cid.clone()));
let ipld = ipld!(Link(cid));
let ipld2 = to_ipld(&cid).unwrap();
assert_eq!(ipld, ipld2);
}
12 changes: 6 additions & 6 deletions key_management/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ mod tests {
fn contains_key() {
let key_vec = construct_priv_keys();
let found_key = key_vec[0].clone();
let addr = key_vec[0].address.clone();
let addr = key_vec[0].address;

let mut wallet = Wallet::new_from_keys(MemKeyStore::new(), key_vec);

Expand All @@ -281,7 +281,7 @@ mod tests {
fn sign() {
let key_vec = construct_priv_keys();
let priv_key_bytes = key_vec[2].key_info.private_key().clone();
let addr = key_vec[2].address.clone();
let addr = key_vec[2].address;
let mut wallet = Wallet::new_from_keys(MemKeyStore::new(), key_vec);
let msg = [0u8; 64];

Expand All @@ -306,7 +306,7 @@ mod tests {

let key_info = wallet.export(&key.address).unwrap();
// test to see if export returns the correct key_info
assert_eq!(key_info, key.key_info.clone());
assert_eq!(key_info, key.key_info);

let new_priv_key = generate(SignatureType::Secp256k1).unwrap();
let pub_key =
Expand Down Expand Up @@ -391,7 +391,7 @@ mod tests {
wallet.keystore.put(test_addr_string, key_info).unwrap();

// check to make sure that the set_default function completed without error
assert!(wallet.set_default(test_addr.clone()).is_ok());
assert!(wallet.set_default(test_addr).is_ok());

// check to make sure that the test_addr is actually the default addr for the wallet
assert_eq!(wallet.get_default().unwrap(), test_addr);
Expand All @@ -402,7 +402,7 @@ mod tests {
let secp_priv_key = generate(SignatureType::Secp256k1).unwrap();
let secp_key_info = KeyInfo::new(SignatureType::Secp256k1, secp_priv_key);
let secp_key = Key::try_from(secp_key_info).unwrap();
let addr = secp_key.address.clone();
let addr = secp_key.address;
let mut wallet = Wallet::new_from_keys(MemKeyStore::new(), vec![secp_key]);

let msg = [0u8; 64];
Expand All @@ -420,7 +420,7 @@ mod tests {
let bls_priv_key = generate(SignatureType::BLS).unwrap();
let bls_key_info = KeyInfo::new(SignatureType::BLS, bls_priv_key);
let bls_key = Key::try_from(bls_key_info).unwrap();
let addr = bls_key.address.clone();
let addr = bls_key.address;
let mut wallet = Wallet::new_from_keys(MemKeyStore::new(), vec![bls_key]);

let msg = [0u8; 64];
Expand Down
16 changes: 8 additions & 8 deletions node/db/tests/subtests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ where
{
let key = [0];
let value = [1];
db.write(key.clone(), value.clone()).unwrap();
db.write(key, value).unwrap();
let res = db.read(key).unwrap().unwrap();
assert_eq!(value.as_ref(), res.as_slice());
}
Expand All @@ -29,7 +29,7 @@ where
{
let key = [0];
let value = [1];
db.write(key.clone(), value.clone()).unwrap();
db.write(key, value).unwrap();
let res = db.exists(key).unwrap();
assert_eq!(res, true);
}
Expand All @@ -49,11 +49,11 @@ where
{
let key = [0];
let value = [1];
db.write(key.clone(), value.clone()).unwrap();
let res = db.exists(key.clone()).unwrap();
db.write(key, value).unwrap();
let res = db.exists(key).unwrap();
assert_eq!(res, true);
db.delete(key.clone()).unwrap();
let res = db.exists(key.clone()).unwrap();
db.delete(key).unwrap();
let res = db.exists(key).unwrap();
assert_eq!(res, false);
}

Expand All @@ -64,7 +64,7 @@ where
let values = [([0], [0]), ([1], [1]), ([2], [2])];
db.bulk_write(&values).unwrap();
for (k, _) in values.iter() {
let res = db.exists(k.clone()).unwrap();
let res = db.exists(*k).unwrap();
assert_eq!(res, true);
}
}
Expand Down Expand Up @@ -96,7 +96,7 @@ where
db.bulk_write(&kvs).unwrap();
db.bulk_delete(&keys).unwrap();
for k in keys.iter() {
let res = db.exists(k.clone()).unwrap();
let res = db.exists(*k).unwrap();
assert_eq!(res, false);
}
}
6 changes: 1 addition & 5 deletions node/forest_libp2p/src/chain_exchange/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,7 @@ fn fts_from_bundle_parts(
let bls_messages = values_from_indexes(&bls_msg_includes[i], &bls_msgs)?;
let secp_messages = values_from_indexes(&secp_msg_includes[i], &secp_msgs)?;

Ok(Block {
header,
secp_messages,
bls_messages,
})
Ok(Block { header, bls_messages, secp_messages })
})
.collect::<Result<_, _>>()?;

Expand Down
Loading

0 comments on commit 1e304d9

Please sign in to comment.