Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 76cc00f

Browse files
authored
Use MAX associated const (#9196)
* Use MAX associated const
1 parent 63ab278 commit 76cc00f

File tree

56 files changed

+178
-178
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+178
-178
lines changed

bin/node/runtime/src/impls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ mod multiplier_tests {
307307
fn weight_to_fee_should_not_overflow_on_large_weights() {
308308
let kb = 1024 as Weight;
309309
let mb = kb * kb;
310-
let max_fm = Multiplier::saturating_from_integer(i128::max_value());
310+
let max_fm = Multiplier::saturating_from_integer(i128::MAX);
311311

312312
// check that for all values it can compute, correctly.
313313
vec![

client/consensus/aura/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ fn slot_author<P: Pair>(slot: Slot, authorities: &[AuthorityId<P>]) -> Option<&A
9797

9898
let idx = *slot % (authorities.len() as u64);
9999
assert!(
100-
idx <= usize::max_value() as u64,
100+
idx <= usize::MAX as u64,
101101
"It is impossible to have a vector with length beyond the address space; qed",
102102
);
103103

client/finality-grandpa/src/communication/gossip.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1468,7 +1468,7 @@ impl<Block: BlockT> GossipValidator<Block> {
14681468
"" => "",
14691469
);
14701470

1471-
let len = std::cmp::min(i32::max_value() as usize, data.len()) as i32;
1471+
let len = std::cmp::min(i32::MAX as usize, data.len()) as i32;
14721472
Action::Discard(Misbehavior::UndecodablePacket(len).cost())
14731473
}
14741474
}

client/informant/src/display.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ fn speed<B: BlockT>(
179179
// algebraic approach and we stay within the realm of integers.
180180
let one_thousand = NumberFor::<B>::from(1_000u32);
181181
let elapsed = NumberFor::<B>::from(
182-
<u32 as TryFrom<_>>::try_from(elapsed_ms).unwrap_or(u32::max_value())
182+
<u32 as TryFrom<_>>::try_from(elapsed_ms).unwrap_or(u32::MAX)
183183
);
184184

185185
let speed = diff.saturating_mul(one_thousand).checked_div(&elapsed)

client/network/src/protocol/notifications/upgrade/notifications.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ where TSubstream: AsyncRead + AsyncWrite + Unpin + Send + 'static,
159159
}
160160

161161
let mut codec = UviBytes::default();
162-
codec.set_max_len(usize::try_from(self.max_notification_size).unwrap_or(usize::max_value()));
162+
codec.set_max_len(usize::try_from(self.max_notification_size).unwrap_or(usize::MAX));
163163

164164
let substream = NotificationsInSubstream {
165165
socket: Framed::new(socket, codec),
@@ -390,7 +390,7 @@ where TSubstream: AsyncRead + AsyncWrite + Unpin + Send + 'static,
390390
}
391391

392392
let mut codec = UviBytes::default();
393-
codec.set_max_len(usize::try_from(self.max_notification_size).unwrap_or(usize::max_value()));
393+
codec.set_max_len(usize::try_from(self.max_notification_size).unwrap_or(usize::MAX));
394394

395395
Ok(NotificationsOutOpen {
396396
handshake,

client/network/src/request_responses.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ impl RequestResponseCodec for GenericCodec {
809809
// Read the length.
810810
let length = unsigned_varint::aio::read_usize(&mut io).await
811811
.map_err(|err| io::Error::new(io::ErrorKind::InvalidInput, err))?;
812-
if length > usize::try_from(self.max_request_size).unwrap_or(usize::max_value()) {
812+
if length > usize::try_from(self.max_request_size).unwrap_or(usize::MAX) {
813813
return Err(io::Error::new(
814814
io::ErrorKind::InvalidInput,
815815
format!("Request size exceeds limit: {} > {}", length, self.max_request_size)
@@ -846,7 +846,7 @@ impl RequestResponseCodec for GenericCodec {
846846
Err(err) => return Err(io::Error::new(io::ErrorKind::InvalidInput, err)),
847847
};
848848

849-
if length > usize::try_from(self.max_response_size).unwrap_or(usize::max_value()) {
849+
if length > usize::try_from(self.max_response_size).unwrap_or(usize::MAX) {
850850
return Err(io::Error::new(
851851
io::ErrorKind::InvalidInput,
852852
format!("Response size exceeds limit: {} > {}", length, self.max_response_size)

client/network/src/service.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,20 +300,20 @@ impl<B: BlockT + 'static, H: ExHashT> NetworkWorker<B, H> {
300300
let yamux_maximum_buffer_size = {
301301
let requests_max = params.network_config
302302
.request_response_protocols.iter()
303-
.map(|cfg| usize::try_from(cfg.max_request_size).unwrap_or(usize::max_value()));
303+
.map(|cfg| usize::try_from(cfg.max_request_size).unwrap_or(usize::MAX));
304304
let responses_max = params.network_config
305305
.request_response_protocols.iter()
306-
.map(|cfg| usize::try_from(cfg.max_response_size).unwrap_or(usize::max_value()));
306+
.map(|cfg| usize::try_from(cfg.max_response_size).unwrap_or(usize::MAX));
307307
let notifs_max = params.network_config
308308
.extra_sets.iter()
309-
.map(|cfg| usize::try_from(cfg.max_notification_size).unwrap_or(usize::max_value()));
309+
.map(|cfg| usize::try_from(cfg.max_notification_size).unwrap_or(usize::MAX));
310310

311311
// A "default" max is added to cover all the other protocols: ping, identify,
312312
// kademlia, block announces, and transactions.
313313
let default_max = cmp::max(
314314
1024 * 1024,
315315
usize::try_from(protocol::BLOCK_ANNOUNCES_TRANSACTIONS_SUBSTREAM_SIZE)
316-
.unwrap_or(usize::max_value())
316+
.unwrap_or(usize::MAX)
317317
);
318318

319319
iter::once(default_max)

client/network/src/service/out_events.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ impl Metrics {
254254
.inc_by(num);
255255
self.notifications_sizes
256256
.with_label_values(&[protocol, "sent", name])
257-
.inc_by(num.saturating_mul(u64::try_from(message.len()).unwrap_or(u64::max_value())));
257+
.inc_by(num.saturating_mul(u64::try_from(message.len()).unwrap_or(u64::MAX)));
258258
}
259259
},
260260
}
@@ -294,7 +294,7 @@ impl Metrics {
294294
.inc();
295295
self.notifications_sizes
296296
.with_label_values(&[&protocol, "received", name])
297-
.inc_by(u64::try_from(message.len()).unwrap_or(u64::max_value()));
297+
.inc_by(u64::try_from(message.len()).unwrap_or(u64::MAX));
298298
}
299299
},
300300
}

client/network/src/service/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ fn lots_of_incoming_peers_works() {
345345
fallback_names: Vec::new(),
346346
max_notification_size: 1024 * 1024,
347347
set_config: config::SetConfig {
348-
in_peers: u32::max_value(),
348+
in_peers: u32::MAX,
349349
.. Default::default()
350350
},
351351
}

client/peerset/src/peersstate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ struct Node {
9797
/// are indices into this `Vec`.
9898
sets: Vec<MembershipState>,
9999

100-
/// Reputation value of the node, between `i32::min_value` (we hate that node) and
101-
/// `i32::max_value` (we love that node).
100+
/// Reputation value of the node, between `i32::MIN` (we hate that node) and
101+
/// `i32::MAX` (we love that node).
102102
reputation: i32,
103103
}
104104

0 commit comments

Comments
 (0)