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>;

0 commit comments

Comments
 (0)