Skip to content

Commit 39e9f7d

Browse files
authored
Fix Rust beta compiler errors (1.77) (#5180)
* Lint fixes * More fixes for beta compiler. * Format fixes * Move `#[allow(dead_code)]` to field level. * Remove old comment. * Update beacon_node/execution_layer/src/test_utils/mod.rs Co-authored-by: João Oliveira <[email protected]> * remove duplicate line
1 parent 8fb6989 commit 39e9f7d

File tree

19 files changed

+64
-46
lines changed

19 files changed

+64
-46
lines changed

beacon_node/beacon_chain/src/attestation_verification.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -539,8 +539,8 @@ impl<'a, T: BeaconChainTypes> IndexedAggregatedAttestation<'a, T> {
539539
Err(e) => return Err(SignatureNotChecked(&signed_aggregate.message.aggregate, e)),
540540
};
541541

542-
let indexed_attestation =
543-
match map_attestation_committee(chain, attestation, |(committee, _)| {
542+
let get_indexed_attestation_with_committee =
543+
|(committee, _): (BeaconCommittee, CommitteesPerSlot)| {
544544
// Note: this clones the signature which is known to be a relatively slow operation.
545545
//
546546
// Future optimizations should remove this clone.
@@ -561,11 +561,17 @@ impl<'a, T: BeaconChainTypes> IndexedAggregatedAttestation<'a, T> {
561561

562562
get_indexed_attestation(committee.committee, attestation)
563563
.map_err(|e| BeaconChainError::from(e).into())
564-
}) {
565-
Ok(indexed_attestation) => indexed_attestation,
566-
Err(e) => return Err(SignatureNotChecked(&signed_aggregate.message.aggregate, e)),
567564
};
568565

566+
let indexed_attestation = match map_attestation_committee(
567+
chain,
568+
attestation,
569+
get_indexed_attestation_with_committee,
570+
) {
571+
Ok(indexed_attestation) => indexed_attestation,
572+
Err(e) => return Err(SignatureNotChecked(&signed_aggregate.message.aggregate, e)),
573+
};
574+
569575
Ok(IndexedAggregatedAttestation {
570576
signed_aggregate,
571577
indexed_attestation,

beacon_node/beacon_chain/src/eth1_chain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ mod test {
967967
let spec = &E::default_spec();
968968
let state: BeaconState<E> = BeaconState::new(0, get_eth1_data(0), spec);
969969

970-
let blocks = vec![];
970+
let blocks = [];
971971

972972
assert_eq!(
973973
get_votes_to_consider(

beacon_node/beacon_chain/src/state_advance_timer.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ const MAX_BLOCK_PRODUCTION_CACHE_DISTANCE: u64 = 4;
5151
#[derive(Debug)]
5252
enum Error {
5353
BeaconChain(BeaconChainError),
54-
HeadMissingFromSnapshotCache(Hash256),
54+
// We don't use the inner value directly, but it's used in the Debug impl.
55+
HeadMissingFromSnapshotCache(#[allow(dead_code)] Hash256),
5556
MaxDistanceExceeded {
5657
current_slot: Slot,
5758
head_slot: Slot,

beacon_node/execution_layer/src/test_utils/mock_builder.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ impl Operation {
5454
}
5555

5656
#[derive(Debug)]
57-
struct Custom(String);
57+
// We don't use the string value directly, but it's used in the Debug impl which is required by `warp::reject::Reject`.
58+
struct Custom(#[allow(dead_code)] String);
5859

5960
impl warp::reject::Reject for Custom {}
6061

beacon_node/execution_layer/src/test_utils/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,8 +599,8 @@ async fn handle_rejection(err: Rejection) -> Result<impl warp::Reply, Infallible
599599
let code;
600600
let message;
601601

602-
if let Some(e) = err.find::<AuthError>() {
603-
message = format!("Authorization error: {:?}", e);
602+
if let Some(AuthError(e)) = err.find::<AuthError>() {
603+
message = format!("Authorization error: {}", e);
604604
code = StatusCode::UNAUTHORIZED;
605605
} else {
606606
message = "BAD_REQUEST".to_string();

beacon_node/http_api/src/attestation_performance.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ const MAX_REQUEST_RANGE_EPOCHS: usize = 100;
1414
const BLOCK_ROOT_CHUNK_SIZE: usize = 100;
1515

1616
#[derive(Debug)]
17+
// We don't use the inner values directly, but they're used in the Debug impl.
1718
enum AttestationPerformanceError {
18-
BlockReplay(BlockReplayError),
19-
BeaconState(BeaconStateError),
20-
ParticipationCache(ParticipationCacheError),
21-
UnableToFindValidator(usize),
19+
BlockReplay(#[allow(dead_code)] BlockReplayError),
20+
BeaconState(#[allow(dead_code)] BeaconStateError),
21+
ParticipationCache(#[allow(dead_code)] ParticipationCacheError),
22+
UnableToFindValidator(#[allow(dead_code)] usize),
2223
}
2324

2425
impl From<BlockReplayError> for AttestationPerformanceError {

beacon_node/http_api/src/block_packing_efficiency.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ use warp_utils::reject::{beacon_chain_error, custom_bad_request, custom_server_e
1919
const BLOCK_ROOT_CHUNK_SIZE: usize = 100;
2020

2121
#[derive(Debug)]
22+
// We don't use the inner values directly, but they're used in the Debug impl.
2223
enum PackingEfficiencyError {
23-
BlockReplay(BlockReplayError),
24-
BeaconState(BeaconStateError),
25-
CommitteeStoreError(Slot),
24+
BlockReplay(#[allow(dead_code)] BlockReplayError),
25+
BeaconState(#[allow(dead_code)] BeaconStateError),
26+
CommitteeStoreError(#[allow(dead_code)] Slot),
2627
InvalidAttestationError,
2728
}
2829

beacon_node/http_api/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ pub fn serve<T: BeaconChainTypes>(
10191019
Ok((
10201020
state
10211021
.get_built_sync_committee(epoch, &chain.spec)
1022-
.map(|committee| committee.clone())
1022+
.cloned()
10231023
.map_err(|e| match e {
10241024
BeaconStateError::SyncCommitteeNotKnown { .. } => {
10251025
warp_utils::reject::custom_bad_request(format!(
@@ -2858,7 +2858,7 @@ pub fn serve<T: BeaconChainTypes>(
28582858
hex::encode(
28592859
meta_data
28602860
.syncnets()
2861-
.map(|x| x.clone())
2861+
.cloned()
28622862
.unwrap_or_default()
28632863
.into_bytes()
28642864
)

beacon_node/lighthouse_network/src/gossipsub/behaviour/tests.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ fn inject_nodes1() -> InjectNodes<IdentityTransform, AllowAllSubscriptionFilter>
174174

175175
fn add_peer<D, F>(
176176
gs: &mut Behaviour<D, F>,
177-
topic_hashes: &Vec<TopicHash>,
177+
topic_hashes: &[TopicHash],
178178
outbound: bool,
179179
explicit: bool,
180180
) -> (PeerId, RpcReceiver)
@@ -187,7 +187,7 @@ where
187187

188188
fn add_peer_with_addr<D, F>(
189189
gs: &mut Behaviour<D, F>,
190-
topic_hashes: &Vec<TopicHash>,
190+
topic_hashes: &[TopicHash],
191191
outbound: bool,
192192
explicit: bool,
193193
address: Multiaddr,
@@ -208,7 +208,7 @@ where
208208

209209
fn add_peer_with_addr_and_kind<D, F>(
210210
gs: &mut Behaviour<D, F>,
211-
topic_hashes: &Vec<TopicHash>,
211+
topic_hashes: &[TopicHash],
212212
outbound: bool,
213213
explicit: bool,
214214
address: Multiaddr,
@@ -3218,7 +3218,7 @@ fn test_scoring_p1() {
32183218
);
32193219
}
32203220

3221-
fn random_message(seq: &mut u64, topics: &Vec<TopicHash>) -> RawMessage {
3221+
fn random_message(seq: &mut u64, topics: &[TopicHash]) -> RawMessage {
32223222
let mut rng = rand::thread_rng();
32233223
*seq += 1;
32243224
RawMessage {
@@ -4080,20 +4080,20 @@ fn test_scoring_p6() {
40804080
//create 5 peers with the same ip
40814081
let addr = Multiaddr::from(Ipv4Addr::new(10, 1, 2, 3));
40824082
let peers = vec![
4083-
add_peer_with_addr(&mut gs, &vec![], false, false, addr.clone()).0,
4084-
add_peer_with_addr(&mut gs, &vec![], false, false, addr.clone()).0,
4085-
add_peer_with_addr(&mut gs, &vec![], true, false, addr.clone()).0,
4086-
add_peer_with_addr(&mut gs, &vec![], true, false, addr.clone()).0,
4087-
add_peer_with_addr(&mut gs, &vec![], true, true, addr.clone()).0,
4083+
add_peer_with_addr(&mut gs, &[], false, false, addr.clone()).0,
4084+
add_peer_with_addr(&mut gs, &[], false, false, addr.clone()).0,
4085+
add_peer_with_addr(&mut gs, &[], true, false, addr.clone()).0,
4086+
add_peer_with_addr(&mut gs, &[], true, false, addr.clone()).0,
4087+
add_peer_with_addr(&mut gs, &[], true, true, addr.clone()).0,
40884088
];
40894089

40904090
//create 4 other peers with other ip
40914091
let addr2 = Multiaddr::from(Ipv4Addr::new(10, 1, 2, 4));
40924092
let others = vec![
4093-
add_peer_with_addr(&mut gs, &vec![], false, false, addr2.clone()).0,
4094-
add_peer_with_addr(&mut gs, &vec![], false, false, addr2.clone()).0,
4095-
add_peer_with_addr(&mut gs, &vec![], true, false, addr2.clone()).0,
4096-
add_peer_with_addr(&mut gs, &vec![], true, false, addr2.clone()).0,
4093+
add_peer_with_addr(&mut gs, &[], false, false, addr2.clone()).0,
4094+
add_peer_with_addr(&mut gs, &[], false, false, addr2.clone()).0,
4095+
add_peer_with_addr(&mut gs, &[], true, false, addr2.clone()).0,
4096+
add_peer_with_addr(&mut gs, &[], true, false, addr2.clone()).0,
40974097
];
40984098

40994099
//no penalties yet

beacon_node/lighthouse_network/tests/common.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ pub fn fork_context(fork_name: ForkName) -> ForkContext {
4242
ForkContext::new::<E>(current_slot, Hash256::zero(), &chain_spec)
4343
}
4444

45-
pub struct Libp2pInstance(LibP2PService<ReqId, E>, exit_future::Signal);
45+
pub struct Libp2pInstance(
46+
LibP2PService<ReqId, E>,
47+
#[allow(dead_code)]
48+
// This field is managed for lifetime purposes may not be used directly, hence the `#[allow(dead_code)]` attribute.
49+
exit_future::Signal,
50+
);
4651

4752
impl std::ops::Deref for Libp2pInstance {
4853
type Target = LibP2PService<ReqId, E>;

beacon_node/network/src/subnet_service/tests/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ mod attestation_service {
253253
&attestation_service.beacon_chain.spec,
254254
)
255255
.unwrap();
256-
let expected = vec![
256+
let expected = [
257257
SubnetServiceMessage::Subscribe(Subnet::Attestation(subnet_id)),
258258
SubnetServiceMessage::Unsubscribe(Subnet::Attestation(subnet_id)),
259259
];

beacon_node/store/src/hot_cold_store.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1344,7 +1344,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
13441344
high_restore_point
13451345
.get_block_root(slot)
13461346
.or_else(|_| high_restore_point.get_oldest_block_root())
1347-
.map(|x| *x)
1347+
.copied()
13481348
.map_err(HotColdDBError::RestorePointBlockHashError)
13491349
}
13501350

common/validator_dir/src/builder.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ impl<'a> Builder<'a> {
214214
.write(true)
215215
.read(true)
216216
.create(true)
217+
.truncate(true)
217218
.open(path)
218219
.map_err(Error::UnableToSaveDepositData)?
219220
.write_all(hex.as_bytes())
@@ -231,6 +232,7 @@ impl<'a> Builder<'a> {
231232
.write(true)
232233
.read(true)
233234
.create(true)
235+
.truncate(true)
234236
.open(path)
235237
.map_err(Error::UnableToSaveDepositAmount)?
236238
.write_all(format!("{}", amount).as_bytes())

consensus/cached_tree_hash/src/impls.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,11 @@ pub fn u64_leaf_count(len: usize) -> usize {
2626

2727
pub fn hash256_iter(
2828
values: &[Hash256],
29-
) -> impl Iterator<Item = [u8; BYTES_PER_CHUNK]> + ExactSizeIterator + '_ {
29+
) -> impl ExactSizeIterator<Item = [u8; BYTES_PER_CHUNK]> + '_ {
3030
values.iter().copied().map(Hash256::to_fixed_bytes)
3131
}
3232

33-
pub fn u64_iter(
34-
values: &[u64],
35-
) -> impl Iterator<Item = [u8; BYTES_PER_CHUNK]> + ExactSizeIterator + '_ {
33+
pub fn u64_iter(values: &[u64]) -> impl ExactSizeIterator<Item = [u8; BYTES_PER_CHUNK]> + '_ {
3634
let type_size = size_of::<u64>();
3735
let vals_per_chunk = BYTES_PER_CHUNK / type_size;
3836
values.chunks(vals_per_chunk).map(move |xs| {

consensus/types/src/beacon_state.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ impl<T: EthSpec> BeaconState<T> {
641641
if self.slot() <= decision_slot {
642642
Ok(block_root)
643643
} else {
644-
self.get_block_root(decision_slot).map(|root| *root)
644+
self.get_block_root(decision_slot).copied()
645645
}
646646
}
647647

@@ -657,7 +657,7 @@ impl<T: EthSpec> BeaconState<T> {
657657
if self.slot() == decision_slot {
658658
Ok(block_root)
659659
} else {
660-
self.get_block_root(decision_slot).map(|root| *root)
660+
self.get_block_root(decision_slot).copied()
661661
}
662662
}
663663

@@ -683,7 +683,7 @@ impl<T: EthSpec> BeaconState<T> {
683683
if self.slot() == decision_slot {
684684
Ok(block_root)
685685
} else {
686-
self.get_block_root(decision_slot).map(|root| *root)
686+
self.get_block_root(decision_slot).copied()
687687
}
688688
}
689689

consensus/types/src/historical_summary.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl<'a, N: Unsigned> CachedTreeHash<TreeHashCache> for HistoricalSummaryCache<'
8181

8282
pub fn leaf_iter(
8383
values: &[HistoricalSummary],
84-
) -> impl Iterator<Item = [u8; BYTES_PER_CHUNK]> + ExactSizeIterator + '_ {
84+
) -> impl ExactSizeIterator<Item = [u8; BYTES_PER_CHUNK]> + '_ {
8585
values
8686
.iter()
8787
.map(|value| value.tree_hash_root())

consensus/types/src/participation_list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub fn leaf_count(len: usize) -> usize {
4343

4444
pub fn leaf_iter(
4545
values: &[ParticipationFlags],
46-
) -> impl Iterator<Item = [u8; BYTES_PER_CHUNK]> + ExactSizeIterator + '_ {
46+
) -> impl ExactSizeIterator<Item = [u8; BYTES_PER_CHUNK]> + '_ {
4747
values.chunks(BYTES_PER_CHUNK).map(|xs| {
4848
// Zero-pad chunks on the right.
4949
let mut chunk = [0u8; BYTES_PER_CHUNK];

database_manager/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ pub fn inspect_db<E: EthSpec>(
356356

357357
let write_result = fs::OpenOptions::new()
358358
.create(true)
359+
.truncate(true)
359360
.write(true)
360361
.open(&file_path)
361362
.map_err(|e| format!("Failed to open file: {:?}", e))

lighthouse/environment/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ impl<E: EthSpec> Environment<E> {
434434
async move { rx.next().await.ok_or("Internal shutdown channel exhausted") };
435435
futures::pin_mut!(inner_shutdown);
436436

437-
match self.runtime().block_on(async {
437+
let register_handlers = async {
438438
let mut handles = vec![];
439439

440440
// setup for handling SIGTERM
@@ -465,7 +465,9 @@ impl<E: EthSpec> Environment<E> {
465465
}
466466

467467
future::select(inner_shutdown, future::select_all(handles.into_iter())).await
468-
}) {
468+
};
469+
470+
match self.runtime().block_on(register_handlers) {
469471
future::Either::Left((Ok(reason), _)) => {
470472
info!(self.log, "Internal shutdown received"; "reason" => reason.message());
471473
Ok(reason)

0 commit comments

Comments
 (0)