Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rust 1.79 lints #5927

Merged
merged 8 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion beacon_node/beacon_chain/src/eth1_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ mod test {
fn get_eth1_data(i: u64) -> Eth1Data {
Eth1Data {
block_hash: Hash256::from_low_u64_be(i),
deposit_root: Hash256::from_low_u64_be(u64::max_value() - i),
deposit_root: Hash256::from_low_u64_be(u64::MAX - i),
deposit_count: i,
}
}
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/beacon_chain/src/validator_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2068,7 +2068,7 @@ pub fn timestamp_now() -> Duration {
}

fn u64_to_i64(n: impl Into<u64>) -> i64 {
i64::try_from(n.into()).unwrap_or(i64::max_value())
i64::try_from(n.into()).unwrap_or(i64::MAX)
}

/// Returns the delay between the start of `block.slot` and `seen_timestamp`.
Expand Down
6 changes: 3 additions & 3 deletions beacon_node/client/src/notifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -721,10 +721,10 @@ fn eth1_logging<T: BeaconChainTypes>(beacon_chain: &BeaconChain<T>, log: &Logger
}
}

/// Returns the peer count, returning something helpful if it's `usize::max_value` (effectively a
/// Returns the peer count, returning something helpful if it's `usize::MAX` (effectively a
/// `None` value).
fn peer_count_pretty(peer_count: usize) -> String {
if peer_count == usize::max_value() {
if peer_count == usize::MAX {
String::from("--")
} else {
format!("{}", peer_count)
Expand Down Expand Up @@ -824,7 +824,7 @@ impl Speedo {

/// Returns the average of the speeds between each observation.
///
/// Does not gracefully handle slots that are above `u32::max_value()`.
/// Does not gracefully handle slots that are above `u32::MAX`.
pub fn slots_per_second(&self) -> Option<f64> {
let speeds = self
.0
Expand Down
9 changes: 3 additions & 6 deletions beacon_node/eth1/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ impl Service {
let max_log_requests_per_update = self
.config()
.max_log_requests_per_update
.unwrap_or_else(usize::max_value);
.unwrap_or(usize::MAX);

let range = {
match new_block_numbers {
Expand Down Expand Up @@ -996,10 +996,7 @@ impl Service {
) -> Result<BlockCacheUpdateOutcome, Error> {
let client = self.client();
let block_cache_truncation = self.config().block_cache_truncation;
let max_blocks_per_update = self
.config()
.max_blocks_per_update
.unwrap_or_else(usize::max_value);
let max_blocks_per_update = self.config().max_blocks_per_update.unwrap_or(usize::MAX);

let range = {
match new_block_numbers {
Expand All @@ -1025,7 +1022,7 @@ impl Service {
let range_size = range.end() - range.start();
let max_size = block_cache_truncation
.map(|n| n as u64)
.unwrap_or_else(u64::max_value);
.unwrap_or_else(|| u64::MAX);
if range_size > max_size {
// If the range of required blocks is larger than `max_size`, drop all
// existing blocks and download `max_size` count of blocks.
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/execution_layer/src/engine_api/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ pub mod deposit_methods {
.ok_or("Block number was not string")?,
)?;

if number <= usize::max_value() as u64 {
if number <= usize::MAX as u64 {
Ok(Block {
hash,
timestamp,
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/execution_layer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2178,7 +2178,7 @@ fn verify_builder_bid<E: EthSpec>(

// Avoid logging values that we can't represent with our Prometheus library.
let payload_value_gwei = bid.data.message.value() / 1_000_000_000;
if payload_value_gwei <= Uint256::from(i64::max_value()) {
if payload_value_gwei <= Uint256::from(i64::MAX) {
metrics::set_gauge_vec(
&metrics::EXECUTION_LAYER_PAYLOAD_BIDS,
&[metrics::BUILDER],
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/execution_layer/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ lazy_static::lazy_static! {
);
pub static ref EXECUTION_LAYER_PAYLOAD_BIDS: Result<IntGaugeVec> = try_create_int_gauge_vec(
"execution_layer_payload_bids",
"The gwei bid value of payloads received by local EEs or builders. Only shows values up to i64::max_value.",
"The gwei bid value of payloads received by local EEs or builders. Only shows values up to i64::MAX.",
&["source"]
);
}
6 changes: 3 additions & 3 deletions beacon_node/http_api/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2266,9 +2266,9 @@ impl ApiTester {
vec![validator_count],
vec![validator_count, 1],
vec![validator_count, 1, 3],
vec![u64::max_value()],
vec![u64::max_value(), 1],
vec![u64::max_value(), 1, 3],
vec![u64::MAX],
vec![u64::MAX, 1],
vec![u64::MAX, 1, 3],
];

interesting.push((0..validator_count).collect());
Expand Down
4 changes: 2 additions & 2 deletions beacon_node/lighthouse_network/src/discovery/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,8 @@ impl<E: EthSpec> Discovery<E> {
/// Updates the `eth2` field of our local ENR.
pub fn update_eth2_enr(&mut self, enr_fork_id: EnrForkId) {
// to avoid having a reference to the spec constant, for the logging we assume
// FAR_FUTURE_EPOCH is u64::max_value()
let next_fork_epoch_log = if enr_fork_id.next_fork_epoch == u64::max_value() {
// FAR_FUTURE_EPOCH is u64::MAX
let next_fork_epoch_log = if enr_fork_id.next_fork_epoch == u64::MAX {
String::from("No other fork")
} else {
format!("{:?}", enr_fork_id.next_fork_epoch)
Expand Down
4 changes: 1 addition & 3 deletions beacon_node/network/src/network_beacon_processor/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -793,9 +793,7 @@ async fn aggregate_attestation_to_unknown_block(import_method: BlockImportMethod
let mut rig = TestRig::new(SMALL_CHAIN).await;

// Empty the op pool.
rig.chain
.op_pool
.prune_attestations(u64::max_value().into());
rig.chain.op_pool.prune_attestations(u64::MAX.into());
assert_eq!(rig.chain.op_pool.num_attestations(), 0);

// Send the attestation but not the block, and check that it was not imported.
Expand Down
4 changes: 2 additions & 2 deletions beacon_node/operation_pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ impl<E: EthSpec> OperationPool<E> {
})
},
|address_change| address_change.as_inner().clone(),
usize::max_value(),
usize::MAX,
);
changes.shuffle(&mut thread_rng());
changes
Expand Down Expand Up @@ -1343,7 +1343,7 @@ mod release_tests {
// Set of indices covered by previous attestations in `best_attestations`.
let mut seen_indices = BTreeSet::<u64>::new();
// Used for asserting that rewards are in decreasing order.
let mut prev_reward = u64::max_value();
let mut prev_reward = u64::MAX;

let mut reward_cache = RewardCache::default();
reward_cache.update(&state).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion common/deposit_contract/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ mod tests {
let mut deposit_data = DepositData {
pubkey: keypair.pk.into(),
withdrawal_credentials: Hash256::from_slice(&[42; 32]),
amount: u64::max_value(),
amount: u64::MAX,
signature: Signature::empty().into(),
};
deposit_data.signature = deposit_data.create_signature(&keypair.sk, spec);
Expand Down
6 changes: 3 additions & 3 deletions consensus/proto_array/src/fork_choice_test_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,17 +285,17 @@ impl ForkChoiceTestDefinition {
}
}

/// Gives a root that is not the zero hash (unless i is `usize::max_value)`.
/// Gives a root that is not the zero hash (unless i is `usize::MAX)`.
fn get_root(i: u64) -> Hash256 {
Hash256::from_low_u64_be(i + 1)
}

/// Gives a hash that is not the zero hash (unless i is `usize::max_value)`.
/// Gives a hash that is not the zero hash (unless i is `usize::MAX)`.
fn get_hash(i: u64) -> ExecutionBlockHash {
ExecutionBlockHash::from_root(get_root(i))
}

/// Gives a checkpoint with a root that is not the zero hash (unless i is `usize::max_value)`.
/// Gives a checkpoint with a root that is not the zero hash (unless i is `usize::MAX)`.
/// `Epoch` will always equal `i`.
fn get_checkpoint(i: u64) -> Checkpoint {
Checkpoint {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
// Ensure that pruning below the prune threshold does not prune.
ops.push(Operation::Prune {
finalized_root: get_root(5),
prune_threshold: usize::max_value(),
prune_threshold: usize::MAX,
expected_len: 11,
});

Expand Down
2 changes: 1 addition & 1 deletion consensus/proto_array/src/proto_array_fork_choice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,7 @@ mod test_compute_deltas {
use super::*;
use types::MainnetEthSpec;

/// Gives a hash that is not the zero hash (unless i is `usize::max_value)`.
/// Gives a hash that is not the zero hash (unless i is `usize::MAX)`.
fn hash_from_index(i: usize) -> Hash256 {
Hash256::from_low_u64_be(i as u64 + 1)
}
Expand Down
14 changes: 7 additions & 7 deletions consensus/safe_arith/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ mod test {

#[test]
fn errors() {
assert!(u32::max_value().safe_add(1).is_err());
assert!(u32::min_value().safe_sub(1).is_err());
assert!(u32::max_value().safe_mul(2).is_err());
assert!(u32::max_value().safe_div(0).is_err());
assert!(u32::max_value().safe_rem(0).is_err());
assert!(u32::max_value().safe_shl(32).is_err());
assert!(u32::max_value().safe_shr(32).is_err());
assert!(u32::MAX.safe_add(1).is_err());
assert!(u32::MIN.safe_sub(1).is_err());
assert!(u32::MAX.safe_mul(2).is_err());
assert!(u32::MAX.safe_div(0).is_err());
assert!(u32::MAX.safe_rem(0).is_err());
assert!(u32::MAX.safe_shl(32).is_err());
assert!(u32::MAX.safe_shr(32).is_err());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl Default for InclusionInfo {
/// Defaults to `delay` at its maximum value and `proposer_index` at zero.
fn default() -> Self {
Self {
delay: u64::max_value(),
delay: u64::MAX,
proposer_index: 0,
}
}
Expand Down
6 changes: 3 additions & 3 deletions consensus/swap_or_not_shuffle/src/compute_shuffled_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::cmp::max;
/// - `list_size == 0`
/// - `index >= list_size`
/// - `list_size > 2**24`
/// - `list_size > usize::max_value() / 2`
/// - `list_size > usize::MAX / 2`
pub fn compute_shuffled_index(
index: usize,
list_size: usize,
Expand All @@ -26,7 +26,7 @@ pub fn compute_shuffled_index(
) -> Option<usize> {
if list_size == 0
|| index >= list_size
|| list_size > usize::max_value() / 2
|| list_size > usize::MAX / 2
|| list_size > 2_usize.pow(24)
{
return None;
Expand Down Expand Up @@ -140,7 +140,7 @@ mod tests {
fn returns_none_for_too_large_list() {
assert_eq!(
None,
compute_shuffled_index(100, usize::max_value() / 2, &[42, 42], 90)
compute_shuffled_index(100, usize::MAX / 2, &[42, 42], 90)
);
}
}
7 changes: 2 additions & 5 deletions consensus/swap_or_not_shuffle/src/shuffle_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl Buf {
/// Returns `None` under any of the following conditions:
/// - `list_size == 0`
/// - `list_size > 2**24`
/// - `list_size > usize::max_value() / 2`
/// - `list_size > usize::MAX / 2`
pub fn shuffle_list(
mut input: Vec<usize>,
rounds: u8,
Expand All @@ -84,10 +84,7 @@ pub fn shuffle_list(
) -> Option<Vec<usize>> {
let list_size = input.len();

if input.is_empty()
|| list_size > usize::max_value() / 2
|| list_size > 2_usize.pow(24)
|| rounds == 0
if input.is_empty() || list_size > usize::MAX / 2 || list_size > 2_usize.pow(24) || rounds == 0
{
return None;
}
Expand Down
4 changes: 2 additions & 2 deletions consensus/types/benches/benches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ fn get_state<E: EthSpec>(validator_count: usize) -> BeaconState<E> {
slashed: false,
activation_eligibility_epoch: Epoch::new(0),
activation_epoch: Epoch::new(0),
exit_epoch: Epoch::from(u64::max_value()),
withdrawable_epoch: Epoch::from(u64::max_value()),
exit_epoch: Epoch::from(u64::MAX),
withdrawable_epoch: Epoch::from(u64::MAX),
})
.collect(),
)
Expand Down
2 changes: 1 addition & 1 deletion consensus/types/src/beacon_state/committee_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl CommitteeCache {
}

// The use of `NonZeroUsize` reduces the maximum number of possible validators by one.
if state.validators().len() == usize::max_value() {
if state.validators().len() == usize::MAX {
return Err(Error::TooManyValidators);
}

Expand Down
8 changes: 4 additions & 4 deletions consensus/types/src/slot_epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl Slot {
}

pub fn max_value() -> Slot {
Slot(u64::max_value())
Slot(u64::MAX)
}
}

Expand All @@ -80,7 +80,7 @@ impl Epoch {
}

pub fn max_value() -> Epoch {
Epoch(u64::max_value())
Epoch(u64::MAX)
}

/// The first slot in the epoch.
Expand Down Expand Up @@ -176,10 +176,10 @@ mod epoch_tests {
let slots_per_epoch = 32;

// The last epoch which can be represented by u64.
let epoch = Epoch::new(u64::max_value() / slots_per_epoch);
let epoch = Epoch::new(u64::MAX / slots_per_epoch);

// A slot number on the epoch should be equal to u64::max_value.
assert_eq!(epoch.end_slot(slots_per_epoch), Slot::new(u64::max_value()));
assert_eq!(epoch.end_slot(slots_per_epoch), Slot::new(u64::MAX));
}

#[test]
Expand Down
Loading