Skip to content

Commit

Permalink
fix(rust): Make Zebra build with the latest nightly Rust (#5738)
Browse files Browse the repository at this point in the history
* 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()

rust-lang/rust#105044

* Remove a redundant into_iter()

* allow(clippy::needless_collect)
  • Loading branch information
teor2345 committed Feb 6, 2023
1 parent 3d37153 commit 249b101
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
9 changes: 8 additions & 1 deletion zebra-chain/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,16 @@ impl Block {

/// Access the [`orchard::Nullifier`]s from all transactions in this block.
pub fn orchard_nullifiers(&self) -> impl Iterator<Item = &orchard::Nullifier> {
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,
Expand Down
1 change: 0 additions & 1 deletion zebra-network/src/isolated/tests/vectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PeerTransport>(
network: Network,
inbound_stream: &mut Framed<PeerTransport, Codec>,
Expand Down
6 changes: 4 additions & 2 deletions zebra-network/src/peer/client/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions zebra-network/src/peer_set/set/tests/prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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>(())
})?;
Expand Down
8 changes: 5 additions & 3 deletions zebra-state/src/service/finalized_state/zebra_db/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 249b101

Please sign in to comment.