Skip to content

Commit b3b6aea

Browse files
authored
Rust 1.85 lints (#7019)
N/A 2 changes: 1. Replace Option::map_or(true, ...) with is_none_or(...) 2. Remove unnecessary `Into::into` blocks where the type conversion is apparent from the types
1 parent ff739d5 commit b3b6aea

File tree

33 files changed

+102
-128
lines changed

33 files changed

+102
-128
lines changed

.github/workflows/test-suite.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ env:
1919
# Disable debug info (see https://github.com/sigp/lighthouse/issues/4005)
2020
RUSTFLAGS: "-D warnings -C debuginfo=0"
2121
# Prevent Github API rate limiting.
22-
LIGHTHOUSE_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
22+
# NOTE: this token is a personal access token on Jimmy's account due to the default GITHUB_TOKEN
23+
# not having access to other repositories. We should eventually devise a better solution here.
24+
LIGHTHOUSE_GITHUB_TOKEN: ${{ secrets.LIGHTHOUSE_GITHUB_TOKEN }}
2325
# Enable self-hosted runners for the sigp repo only.
2426
SELF_HOSTED_RUNNERS: ${{ github.repository == 'sigp/lighthouse' }}
2527
# Self-hosted runners need to reference a different host for `./watch` tests.

beacon_node/beacon_chain/src/attestation_verification.rs

+13-15
Original file line numberDiff line numberDiff line change
@@ -1450,19 +1450,17 @@ where
14501450
return Err(Error::UnknownTargetRoot(target.root));
14511451
}
14521452

1453-
chain
1454-
.with_committee_cache(target.root, attestation_epoch, |committee_cache, _| {
1455-
let committees_per_slot = committee_cache.committees_per_slot();
1456-
1457-
Ok(committee_cache
1458-
.get_beacon_committees_at_slot(attestation.data().slot)
1459-
.map(|committees| map_fn((committees, committees_per_slot)))
1460-
.unwrap_or_else(|_| {
1461-
Err(Error::NoCommitteeForSlotAndIndex {
1462-
slot: attestation.data().slot,
1463-
index: attestation.committee_index().unwrap_or(0),
1464-
})
1465-
}))
1466-
})
1467-
.map_err(BeaconChainError::from)?
1453+
chain.with_committee_cache(target.root, attestation_epoch, |committee_cache, _| {
1454+
let committees_per_slot = committee_cache.committees_per_slot();
1455+
1456+
Ok(committee_cache
1457+
.get_beacon_committees_at_slot(attestation.data().slot)
1458+
.map(|committees| map_fn((committees, committees_per_slot)))
1459+
.unwrap_or_else(|_| {
1460+
Err(Error::NoCommitteeForSlotAndIndex {
1461+
slot: attestation.data().slot,
1462+
index: attestation.committee_index().unwrap_or(0),
1463+
})
1464+
}))
1465+
})?
14681466
}

beacon_node/beacon_chain/src/beacon_chain.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -6506,9 +6506,9 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
65066506

65076507
/// Returns `true` if the given slot is prior to the `bellatrix_fork_epoch`.
65086508
pub fn slot_is_prior_to_bellatrix(&self, slot: Slot) -> bool {
6509-
self.spec.bellatrix_fork_epoch.map_or(true, |bellatrix| {
6510-
slot.epoch(T::EthSpec::slots_per_epoch()) < bellatrix
6511-
})
6509+
self.spec
6510+
.bellatrix_fork_epoch
6511+
.is_none_or(|bellatrix| slot.epoch(T::EthSpec::slots_per_epoch()) < bellatrix)
65126512
}
65136513

65146514
/// Returns the value of `execution_optimistic` for `block`.

beacon_node/beacon_chain/src/block_times_cache.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ impl BlockTimesCache {
173173
if block_times
174174
.timestamps
175175
.all_blobs_observed
176-
.map_or(true, |prev| timestamp > prev)
176+
.is_none_or(|prev| timestamp > prev)
177177
{
178178
block_times.timestamps.all_blobs_observed = Some(timestamp);
179179
}
@@ -195,7 +195,7 @@ impl BlockTimesCache {
195195
.entry(block_root)
196196
.or_insert_with(|| BlockTimesCacheValue::new(slot));
197197
let existing_timestamp = field(&mut block_times.timestamps);
198-
if existing_timestamp.map_or(true, |prev| timestamp < prev) {
198+
if existing_timestamp.is_none_or(|prev| timestamp < prev) {
199199
*existing_timestamp = Some(timestamp);
200200
}
201201
}

beacon_node/beacon_chain/src/data_availability_checker/overflow_lru_cache.rs

-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,6 @@ impl<E: EthSpec> PendingComponents<E> {
307307
.map(|b| b.map(|b| b.to_blob()))
308308
.take(num_blobs_expected)
309309
.collect::<Option<Vec<_>>>()
310-
.map(Into::into)
311310
else {
312311
return Err(AvailabilityCheckError::Unexpected);
313312
};

beacon_node/beacon_chain/src/shuffling_cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ impl ShufflingCache {
138138
.get(&key)
139139
// Replace the committee if it's not present or if it's a promise. A bird in the hand is
140140
// worth two in the promise-bush!
141-
.map_or(true, CacheItem::is_promise)
141+
.is_none_or(CacheItem::is_promise)
142142
{
143143
self.insert_cache_item(
144144
key,

beacon_node/beacon_chain/src/validator_monitor.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ impl<E: EthSpec> ValidatorMonitor<E> {
628628
// the proposer shuffling cache lock when there are lots of missed blocks.
629629
if proposers_per_epoch
630630
.as_ref()
631-
.map_or(true, |(_, cached_epoch)| *cached_epoch != slot_epoch)
631+
.is_none_or(|(_, cached_epoch)| *cached_epoch != slot_epoch)
632632
{
633633
proposers_per_epoch = self
634634
.get_proposers_by_epoch_from_cache(

beacon_node/client/src/notifier.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ pub fn spawn_notifier<T: BeaconChainTypes>(
187187
let is_backfilling = matches!(current_sync_state, SyncState::BackFillSyncing { .. });
188188
if is_backfilling
189189
&& last_backfill_log_slot
190-
.map_or(true, |slot| slot + BACKFILL_LOG_INTERVAL <= current_slot)
190+
.is_none_or(|slot| slot + BACKFILL_LOG_INTERVAL <= current_slot)
191191
{
192192
last_backfill_log_slot = Some(current_slot);
193193

beacon_node/execution_layer/src/test_utils/execution_block_generator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ impl<E: EthSpec> ExecutionBlockGenerator<E> {
448448
if self
449449
.head_block
450450
.as_ref()
451-
.map_or(true, |head| head.block_hash() == last_block_hash)
451+
.is_none_or(|head| head.block_hash() == last_block_hash)
452452
{
453453
self.head_block = Some(block.clone());
454454
}

beacon_node/genesis/src/eth1_genesis_service.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ impl Eth1GenesisService {
263263
// again later.
264264
if eth1_service
265265
.highest_safe_block()
266-
.map_or(true, |n| block.number > n)
266+
.is_none_or(|n| block.number > n)
267267
{
268268
continue;
269269
}

beacon_node/http_api/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1939,10 +1939,10 @@ pub fn serve<T: BeaconChainTypes>(
19391939
query: api_types::AttestationPoolQuery| {
19401940
task_spawner.blocking_response_task(Priority::P1, move || {
19411941
let query_filter = |data: &AttestationData| {
1942-
query.slot.map_or(true, |slot| slot == data.slot)
1942+
query.slot.is_none_or(|slot| slot == data.slot)
19431943
&& query
19441944
.committee_index
1945-
.map_or(true, |index| index == data.index)
1945+
.is_none_or(|index| index == data.index)
19461946
};
19471947

19481948
let mut attestations = chain.op_pool.get_filtered_attestations(query_filter);
@@ -3159,11 +3159,11 @@ pub fn serve<T: BeaconChainTypes>(
31593159
peer_info.connection_status(),
31603160
);
31613161

3162-
let state_matches = query.state.as_ref().map_or(true, |states| {
3162+
let state_matches = query.state.as_ref().is_none_or(|states| {
31633163
states.iter().any(|state_param| *state_param == state)
31643164
});
31653165
let direction_matches =
3166-
query.direction.as_ref().map_or(true, |directions| {
3166+
query.direction.as_ref().is_none_or(|directions| {
31673167
directions.iter().any(|dir_param| *dir_param == direction)
31683168
});
31693169

beacon_node/http_api/src/produce_block.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ pub async fn produce_blinded_block_v2<T: BeaconChainTypes>(
147147
.produce_block_with_verification(
148148
randao_reveal,
149149
slot,
150-
query.graffiti.map(Into::into),
150+
query.graffiti,
151151
randao_verification,
152152
None,
153153
BlockProductionVersion::BlindedV2,
@@ -178,7 +178,7 @@ pub async fn produce_block_v2<T: BeaconChainTypes>(
178178
.produce_block_with_verification(
179179
randao_reveal,
180180
slot,
181-
query.graffiti.map(Into::into),
181+
query.graffiti,
182182
randao_verification,
183183
None,
184184
BlockProductionVersion::FullV2,

beacon_node/http_api/src/validators.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub fn get_beacon_state_validators<T: BeaconChainTypes>(
2929
.enumerate()
3030
// filter by validator id(s) if provided
3131
.filter(|(index, (validator, _))| {
32-
ids_filter_set.as_ref().map_or(true, |ids_set| {
32+
ids_filter_set.as_ref().is_none_or(|ids_set| {
3333
ids_set.contains(&ValidatorId::PublicKey(validator.pubkey))
3434
|| ids_set.contains(&ValidatorId::Index(*index as u64))
3535
})
@@ -42,7 +42,7 @@ pub fn get_beacon_state_validators<T: BeaconChainTypes>(
4242
far_future_epoch,
4343
);
4444

45-
let status_matches = query_statuses.as_ref().map_or(true, |statuses| {
45+
let status_matches = query_statuses.as_ref().is_none_or(|statuses| {
4646
statuses.contains(&status)
4747
|| statuses.contains(&status.superstatus())
4848
});
@@ -92,7 +92,7 @@ pub fn get_beacon_state_validator_balances<T: BeaconChainTypes>(
9292
.enumerate()
9393
// filter by validator id(s) if provided
9494
.filter(|(index, (validator, _))| {
95-
ids_filter_set.as_ref().map_or(true, |ids_set| {
95+
ids_filter_set.as_ref().is_none_or(|ids_set| {
9696
ids_set.contains(&ValidatorId::PublicKey(validator.pubkey))
9797
|| ids_set.contains(&ValidatorId::Index(*index as u64))
9898
})

beacon_node/http_api/tests/tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2450,8 +2450,8 @@ impl ApiTester {
24502450
};
24512451

24522452
let state_match =
2453-
states.map_or(true, |states| states.contains(&PeerState::Connected));
2454-
let dir_match = dirs.map_or(true, |dirs| dirs.contains(&PeerDirection::Inbound));
2453+
states.is_none_or(|states| states.contains(&PeerState::Connected));
2454+
let dir_match = dirs.is_none_or(|dirs| dirs.contains(&PeerDirection::Inbound));
24552455

24562456
let mut expected_peers = Vec::new();
24572457
if state_match && dir_match {

beacon_node/lighthouse_network/src/peer_manager/network_behaviour.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ impl<E: EthSpec> NetworkBehaviour for PeerManager<E> {
201201
.peers
202202
.read()
203203
.peer_info(&peer_id)
204-
.map_or(true, |peer| !peer.has_future_duty())
204+
.is_none_or(|peer| !peer.has_future_duty())
205205
{
206206
return Err(ConnectionDenied::new(
207207
"Connection to peer rejected: too many connections",
@@ -240,7 +240,7 @@ impl<E: EthSpec> NetworkBehaviour for PeerManager<E> {
240240
.peers
241241
.read()
242242
.peer_info(&peer_id)
243-
.map_or(true, |peer| !peer.has_future_duty())
243+
.is_none_or(|peer| !peer.has_future_duty())
244244
{
245245
return Err(ConnectionDenied::new(
246246
"Connection to peer rejected: too many connections",

beacon_node/network/src/network_beacon_processor/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ const BLOB_PUBLICATION_EXP_FACTOR: usize = 2;
7979

8080
impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
8181
fn try_send(&self, event: BeaconWorkEvent<T::EthSpec>) -> Result<(), Error<T::EthSpec>> {
82-
self.beacon_processor_send
83-
.try_send(event)
84-
.map_err(Into::into)
82+
self.beacon_processor_send.try_send(event)
8583
}
8684

8785
/// Create a new `Work` event for some `SingleAttestation`.

beacon_node/operation_pool/src/bls_to_execution_changes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl<E: EthSpec> BlsToExecutionChanges<E> {
112112
head_state
113113
.validators()
114114
.get(validator_index as usize)
115-
.map_or(true, |validator| {
115+
.is_none_or(|validator| {
116116
let prune = validator.has_execution_withdrawal_credential(spec)
117117
&& head_block
118118
.message()

beacon_node/operation_pool/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ fn prune_validator_hash_map<T, F, E: EthSpec>(
767767
&& head_state
768768
.validators()
769769
.get(validator_index as usize)
770-
.map_or(true, |validator| !prune_if(validator_index, validator))
770+
.is_none_or(|validator| !prune_if(validator_index, validator))
771771
});
772772
}
773773

beacon_node/operation_pool/src/reward_cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl RewardCache {
8383
if self
8484
.initialization
8585
.as_ref()
86-
.map_or(true, |init| *init != new_init)
86+
.is_none_or(|init| *init != new_init)
8787
{
8888
self.update_previous_epoch_participation(state)
8989
.map_err(OpPoolError::RewardCacheUpdatePrevEpoch)?;

beacon_node/store/src/hot_cold_store.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
903903
state_root: &Hash256,
904904
summary: HotStateSummary,
905905
) -> Result<(), Error> {
906-
self.hot_db.put(state_root, &summary).map_err(Into::into)
906+
self.hot_db.put(state_root, &summary)
907907
}
908908

909909
/// Store a state in the store.
@@ -1248,7 +1248,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
12481248
state_root.as_slice().to_vec(),
12491249
));
12501250

1251-
if slot.map_or(true, |slot| slot % E::slots_per_epoch() == 0) {
1251+
if slot.is_none_or(|slot| slot % E::slots_per_epoch() == 0) {
12521252
key_value_batch.push(KeyValueStoreOp::DeleteKey(
12531253
DBColumn::BeaconState,
12541254
state_root.as_slice().to_vec(),

beacon_node/store/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -195,15 +195,13 @@ pub trait ItemStore<E: EthSpec>: KeyValueStore<E> + Sync + Send + Sized + 'stati
195195
let key = key.as_slice();
196196

197197
self.put_bytes(column, key, &item.as_store_bytes())
198-
.map_err(Into::into)
199198
}
200199

201200
fn put_sync<I: StoreItem>(&self, key: &Hash256, item: &I) -> Result<(), Error> {
202201
let column = I::db_column();
203202
let key = key.as_slice();
204203

205204
self.put_bytes_sync(column, key, &item.as_store_bytes())
206-
.map_err(Into::into)
207205
}
208206

209207
/// Retrieve an item from `Self`.

common/account_utils/src/validator_definitions.rs

-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ impl SigningDefinition {
115115
voting_keystore_password_path: Some(path),
116116
..
117117
} => read_password_string(path)
118-
.map(Into::into)
119118
.map(Option::Some)
120119
.map_err(Error::UnableToReadKeystorePassword),
121120
SigningDefinition::LocalKeystore { .. } => Err(Error::KeystoreWithoutPassword),

consensus/state_processing/src/per_block_processing/block_signature_verifier.rs

-1
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,6 @@ where
293293
)?);
294294
Ok(())
295295
})
296-
.map_err(Error::into)
297296
}
298297

299298
/// Includes all signatures in `self.block.body.voluntary_exits` for verification.

consensus/types/src/beacon_block_body.rs

+1
Original file line numberDiff line numberDiff line change
@@ -971,6 +971,7 @@ impl<E: EthSpec> From<BeaconBlockBody<E, FullPayload<E>>>
971971
Option<ExecutionPayload<E>>,
972972
)
973973
{
974+
#[allow(clippy::useless_conversion)] // Not a useless conversion
974975
fn from(body: BeaconBlockBody<E, FullPayload<E>>) -> Self {
975976
map_beacon_block_body!(body, |inner, cons| {
976977
let (block, payload) = inner.into();

consensus/types/src/runtime_var_list.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,13 @@ impl<T: Decode> RuntimeVariableList<T> {
134134
)));
135135
}
136136

137-
bytes
138-
.chunks(<T as Decode>::ssz_fixed_len())
139-
.try_fold(Vec::with_capacity(num_items), |mut vec, chunk| {
137+
bytes.chunks(<T as Decode>::ssz_fixed_len()).try_fold(
138+
Vec::with_capacity(num_items),
139+
|mut vec, chunk| {
140140
vec.push(<T as Decode>::from_ssz_bytes(chunk)?);
141141
Ok(vec)
142-
})
143-
.map(Into::into)?
142+
},
143+
)?
144144
} else {
145145
ssz::decode_list_of_variable_length_items(bytes, Some(max_len))?
146146
};

slasher/src/database.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ impl<E: EthSpec> SlasherDB<E> {
665665
target: Epoch,
666666
prev_max_target: Option<Epoch>,
667667
) -> Result<Option<CompactAttesterRecord>, Error> {
668-
if prev_max_target.map_or(true, |prev_max| target > prev_max) {
668+
if prev_max_target.is_none_or(|prev_max| target > prev_max) {
669669
return Ok(None);
670670
}
671671

0 commit comments

Comments
 (0)