From 26ff1b4fb024fb7cb778df90e14a0903804d9ca1 Mon Sep 17 00:00:00 2001 From: teor Date: Wed, 30 Nov 2022 17:03:24 +1000 Subject: [PATCH] fix(rust): Make Zebra build with the latest nightly Rust (#5738) * Remove an unused async track_caller which will soon become a warning * Explicitly drop unused futures * Work around a compiler panic (ICE) with flat_map() https://github.com/rust-lang/rust/issues/105044 * Remove a redundant into_iter() * allow(clippy::needless_collect) --- zebra-chain/src/block.rs | 9 ++++++++- zebra-network/src/isolated/tests/vectors.rs | 1 - zebra-network/src/peer/client/tests.rs | 6 ++++-- zebra-network/src/peer_set/set/tests/prop.rs | 9 ++++++--- .../src/service/finalized_state/zebra_db/metrics.rs | 8 +++++--- 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/zebra-chain/src/block.rs b/zebra-chain/src/block.rs index a7242641160..53bf21f5318 100644 --- a/zebra-chain/src/block.rs +++ b/zebra-chain/src/block.rs @@ -149,9 +149,16 @@ impl Block { /// Access the [`orchard::Nullifier`]s from all transactions in this block. pub fn orchard_nullifiers(&self) -> impl Iterator { - self.transactions + // Work around a compiler panic (ICE) with flat_map(): + // https://github.com/rust-lang/rust/issues/105044 + #[allow(clippy::needless_collect)] + let nullifiers: Vec<_> = self + .transactions .iter() .flat_map(|transaction| transaction.orchard_nullifiers()) + .collect(); + + nullifiers.into_iter() } /// Count how many Sapling transactions exist in a block, diff --git a/zebra-network/src/isolated/tests/vectors.rs b/zebra-network/src/isolated/tests/vectors.rs index a182ebc133b..d6e0f815847 100644 --- a/zebra-network/src/isolated/tests/vectors.rs +++ b/zebra-network/src/isolated/tests/vectors.rs @@ -120,7 +120,6 @@ async fn connect_isolated_sends_anonymised_version_message_mem_net(network: Netw /// Wait to receive a version message on `inbound_stream`, /// then check that it is correctly anonymised. -#[track_caller] async fn check_version_message( network: Network, inbound_stream: &mut Framed, diff --git a/zebra-network/src/peer/client/tests.rs b/zebra-network/src/peer/client/tests.rs index 4b3d0eef15b..50730244d86 100644 --- a/zebra-network/src/peer/client/tests.rs +++ b/zebra-network/src/peer/client/tests.rs @@ -90,10 +90,12 @@ impl ClientTestHarness { /// Drops the mocked heartbeat shutdown receiver endpoint. pub fn drop_heartbeat_shutdown_receiver(&mut self) { - let _ = self + let hearbeat_future = self .shutdown_receiver .take() - .expect("heartbeat shutdown receiver endpoint has already been dropped"); + .expect("unexpected test failure: heartbeat shutdown receiver endpoint has already been dropped"); + + std::mem::drop(hearbeat_future); } /// Closes the receiver endpoint of [`ClientRequest`]s that are supposed to be sent to the diff --git a/zebra-network/src/peer_set/set/tests/prop.rs b/zebra-network/src/peer_set/set/tests/prop.rs index efd7a8968c9..24b3c9ab529 100644 --- a/zebra-network/src/peer_set/set/tests/prop.rs +++ b/zebra-network/src/peer_set/set/tests/prop.rs @@ -145,7 +145,8 @@ proptest! { } // Send a request to all peers - let _ = peer_set.route_broadcast(Request::AdvertiseBlock(block_hash)); + let response_future = peer_set.route_broadcast(Request::AdvertiseBlock(block_hash)); + std::mem::drop(response_future); // Check how many peers received the request let mut received = 0; @@ -213,7 +214,8 @@ proptest! { let number_of_peers_to_broadcast = peer_set.number_of_peers_to_broadcast(); // Send a request to all peers we have now - let _ = peer_set.route_broadcast(Request::AdvertiseBlock(block_hash)); + let response_future = peer_set.route_broadcast(Request::AdvertiseBlock(block_hash)); + std::mem::drop(response_future); // Check how many peers received the request let mut received = 0; @@ -273,7 +275,8 @@ proptest! { } // this will panic as expected - let _ = peer_set.route_broadcast(Request::AdvertiseBlock(block_hash)); + let response_future = peer_set.route_broadcast(Request::AdvertiseBlock(block_hash)); + std::mem::drop(response_future); Ok::<_, TestCaseError>(()) })?; diff --git a/zebra-state/src/service/finalized_state/zebra_db/metrics.rs b/zebra-state/src/service/finalized_state/zebra_db/metrics.rs index 1f01f028dc0..9f102ec80ed 100644 --- a/zebra-state/src/service/finalized_state/zebra_db/metrics.rs +++ b/zebra-state/src/service/finalized_state/zebra_db/metrics.rs @@ -33,11 +33,13 @@ pub(crate) fn block_precommit_metrics(block: &Block, hash: block::Hash, height: .flat_map(|t| t.sapling_nullifiers()) .count(); - let orchard_nullifier_count = block + // Work around a compiler panic (ICE) with flat_map(): + // https://github.com/rust-lang/rust/issues/105044 + let orchard_nullifier_count: usize = block .transactions .iter() - .flat_map(|t| t.orchard_nullifiers()) - .count(); + .map(|t| t.orchard_nullifiers().count()) + .sum(); tracing::debug!( ?hash,