Skip to content

Commit

Permalink
chore: Fix cargo clippy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
larseggert authored and Ralith committed Nov 18, 2024
1 parent 98a1050 commit f8b8c50
Show file tree
Hide file tree
Showing 15 changed files with 28 additions and 35 deletions.
2 changes: 1 addition & 1 deletion perf/src/bin/perf_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ async fn request(

let send_stream_stats = stream_stats.new_sender(&send, upload);

const DATA: [u8; 1024 * 1024] = [42; 1024 * 1024];
static DATA: [u8; 1024 * 1024] = [42; 1024 * 1024];
while upload > 0 {
let chunk_len = upload.min(DATA.len() as u64);
send.write_chunk(Bytes::from_static(&DATA[..chunk_len as usize]))
Expand Down
2 changes: 1 addition & 1 deletion perf/src/bin/perf_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ async fn drain_stream(mut stream: quinn::RecvStream) -> Result<()> {
}

async fn respond(mut bytes: u64, mut stream: quinn::SendStream) -> Result<()> {
const DATA: [u8; 1024 * 1024] = [42; 1024 * 1024];
static DATA: [u8; 1024 * 1024] = [42; 1024 * 1024];

while bytes > 0 {
let chunk_len = bytes.min(DATA.len() as u64);
Expand Down
4 changes: 1 addition & 3 deletions quinn-proto/src/connection/ack_frequency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,7 @@ impl AckFrequencyState {
) -> Result<bool, TransportError> {
if self
.last_ack_frequency_frame
.map_or(false, |highest_sequence_nr| {
frame.sequence.into_inner() <= highest_sequence_nr
})
.is_some_and(|highest_sequence_nr| frame.sequence.into_inner() <= highest_sequence_nr)
{
return Ok(false);
}
Expand Down
16 changes: 6 additions & 10 deletions quinn-proto/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -973,14 +973,10 @@ impl Connection {
// Send MTU probe if necessary
if buf.is_empty() && self.state.is_established() {
let space_id = SpaceId::Data;
let probe_size = match self
let probe_size = self
.path
.mtud
.poll_transmit(now, self.packet_number_filter.peek(&self.spaces[space_id]))
{
Some(next_probe_size) => next_probe_size,
None => return None,
};
.poll_transmit(now, self.packet_number_filter.peek(&self.spaces[space_id]))?;

let buf_capacity = probe_size as usize;
buf.reserve(buf_capacity);
Expand Down Expand Up @@ -1655,7 +1651,7 @@ impl Connection {
None if self
.path
.first_packet_after_rtt_sample
.map_or(false, |x| x < (pn_space, packet)) =>
.is_some_and(|x| x < (pn_space, packet)) =>
{
persistent_congestion_start = Some(info.time_sent);
}
Expand Down Expand Up @@ -2230,7 +2226,7 @@ impl Connection {
let _guard = span.enter();

let is_duplicate = |n| self.spaces[packet.header.space()].dedup.insert(n);
if number.map_or(false, is_duplicate) {
if number.is_some_and(is_duplicate) {
debug!("discarding possible duplicate packet");
return;
} else if self.state.is_handshake() && packet.header.is_short() {
Expand Down Expand Up @@ -3544,13 +3540,13 @@ impl Connection {
|| self
.prev_path
.as_ref()
.map_or(false, |(_, x)| x.challenge_pending)
.is_some_and(|(_, x)| x.challenge_pending)
|| !self.path_responses.is_empty()
|| self
.datagrams
.outgoing
.front()
.map_or(false, |x| x.size(true) <= max_size)
.is_some_and(|x| x.size(true) <= max_size)
}

/// Update counters to account for a packet becoming acknowledged, lost, or abandoned
Expand Down
2 changes: 1 addition & 1 deletion quinn-proto/src/connection/mtud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ impl BlackHoleDetector {
let end_last_burst = self
.current_loss_burst
.as_ref()
.map_or(false, |current| pn - current.latest_non_probe != 1);
.is_some_and(|current| pn - current.latest_non_probe != 1);

if end_last_burst {
self.finish_loss_burst();
Expand Down
2 changes: 1 addition & 1 deletion quinn-proto/src/connection/packet_crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ pub(super) fn decrypt_packet_body(

if crypto_update {
// Validate incoming key update
if number <= rx_packet || prev_crypto.map_or(false, |x| x.update_unacked) {
if number <= rx_packet || prev_crypto.is_some_and(|x| x.update_unacked) {
return Err(Some(TransportError::KEY_UPDATE_ERROR("")));
}
}
Expand Down
2 changes: 1 addition & 1 deletion quinn-proto/src/connection/spaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ impl PacketNumberFilter {
if space_id == SpaceId::Data
&& self
.prev_skipped_packet_number
.map_or(false, |x| range.contains(&x))
.is_some_and(|x| range.contains(&x))
{
return Err(TransportError::PROTOCOL_VIOLATION("unsent packet acked"));
}
Expand Down
4 changes: 2 additions & 2 deletions quinn-proto/src/connection/streams/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ impl StreamsState {
self.send
.get(&stream.id)
.and_then(|s| s.as_ref())
.map_or(false, |s| !s.is_reset())
.is_some_and(|s| !s.is_reset())
})
}

Expand All @@ -406,7 +406,7 @@ impl StreamsState {
.get(&id)
.and_then(|s| s.as_ref())
.and_then(|s| s.as_open_recv())
.map_or(false, |s| s.can_send_flow_control())
.is_some_and(|s| s.can_send_flow_control())
}

pub(in crate::connection) fn write_control_frames(
Expand Down
2 changes: 1 addition & 1 deletion quinn-proto/src/connection/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ impl TimerTable {
}

pub(super) fn is_expired(&self, timer: Timer, after: Instant) -> bool {
self.data[timer as usize].map_or(false, |x| x <= after)
self.data[timer as usize].is_some_and(|x| x <= after)
}
}
6 changes: 3 additions & 3 deletions quinn-proto/src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,11 @@ impl Endpoint {
if incoming_buffer
.total_bytes
.checked_add(datagram_len as u64)
.map_or(false, |n| n <= config.incoming_buffer_size)
.is_some_and(|n| n <= config.incoming_buffer_size)
&& self
.all_incoming_buffers_total_bytes
.checked_add(datagram_len as u64)
.map_or(false, |n| n <= config.incoming_buffer_size_total)
.is_some_and(|n| n <= config.incoming_buffer_size_total)
{
incoming_buffer.datagrams.push(event);
incoming_buffer.total_bytes += datagram_len as u64;
Expand Down Expand Up @@ -334,7 +334,7 @@ impl Endpoint {
) -> Option<Transmit> {
if self
.last_stateless_reset
.map_or(false, |last| last + self.config.min_reset_interval > now)
.is_some_and(|last| last + self.config.min_reset_interval > now)
{
debug!("ignoring unexpected packet within minimum stateless reset interval");
return None;
Expand Down
2 changes: 1 addition & 1 deletion quinn-proto/src/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ impl PacketNumber {
// The following code calculates a candidate value and makes sure it's within the packet
// number window.
let candidate = (expected & !mask) | truncated;
if expected.checked_sub(hwin).map_or(false, |x| candidate <= x) {
if expected.checked_sub(hwin).is_some_and(|x| candidate <= x) {
candidate + win
} else if candidate > expected + hwin && candidate > win {
candidate - win
Expand Down
2 changes: 1 addition & 1 deletion quinn-proto/src/range_set/btree_range_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl RangeSet {
}

pub fn contains(&self, x: u64) -> bool {
self.pred(x).map_or(false, |(_, end)| end > x)
self.pred(x).is_some_and(|(_, end)| end > x)
}

pub fn insert_one(&mut self, x: u64) -> bool {
Expand Down
4 changes: 2 additions & 2 deletions quinn-proto/src/tests/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ impl TestEndpoint {
let buffer_size = self.endpoint.config().get_max_udp_payload_size() as usize;
let mut buf = Vec::with_capacity(buffer_size);

while self.inbound.front().map_or(false, |x| x.0 <= now) {
while self.inbound.front().is_some_and(|x| x.0 <= now) {
let (recv_time, ecn, packet) = self.inbound.pop_front().unwrap();
if let Some(event) = self
.endpoint
Expand Down Expand Up @@ -415,7 +415,7 @@ impl TestEndpoint {
loop {
let mut endpoint_events: Vec<(ConnectionHandle, EndpointEvent)> = vec![];
for (ch, conn) in self.connections.iter_mut() {
if self.timeout.map_or(false, |x| x <= now) {
if self.timeout.is_some_and(|x| x <= now) {
self.timeout = None;
conn.handle_timeout(now);
}
Expand Down
7 changes: 3 additions & 4 deletions quinn-proto/src/transport_parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl TransportParameters {
initial_max_stream_data_uni: config.stream_receive_window,
max_udp_payload_size: endpoint_config.max_udp_payload_size,
max_idle_timeout: config.max_idle_timeout.unwrap_or(VarInt(0)),
disable_active_migration: server_config.map_or(false, |c| !c.migration),
disable_active_migration: server_config.is_some_and(|c| !c.migration),
active_connection_id_limit: if cid_gen.cid_len() == 0 {
2 // i.e. default, i.e. unsent
} else {
Expand Down Expand Up @@ -446,7 +446,7 @@ impl TransportParameters {
|| params.initial_max_streams_bidi.0 > MAX_STREAM_COUNT
|| params.initial_max_streams_uni.0 > MAX_STREAM_COUNT
// https://www.ietf.org/archive/id/draft-ietf-quic-ack-frequency-08.html#section-3-4
|| params.min_ack_delay.map_or(false, |min_ack_delay| {
|| params.min_ack_delay.is_some_and(|min_ack_delay| {
// min_ack_delay uses microseconds, whereas max_ack_delay uses milliseconds
min_ack_delay.0 > params.max_ack_delay.0 * 1_000
})
Expand All @@ -458,8 +458,7 @@ impl TransportParameters {
|| params.stateless_reset_token.is_some()))
// https://www.rfc-editor.org/rfc/rfc9000.html#section-18.2-4.38.1
|| params
.preferred_address
.map_or(false, |x| x.connection_id.is_empty())
.preferred_address.is_some_and(|x| x.connection_id.is_empty())
{
return Err(Error::IllegalValue);
}
Expand Down
6 changes: 3 additions & 3 deletions quinn/examples/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ fn main() {
async fn run(options: Opt) -> Result<()> {
let (certs, key) = if let (Some(key_path), Some(cert_path)) = (&options.key, &options.cert) {
let key = fs::read(key_path).context("failed to read private key")?;
let key = if key_path.extension().map_or(false, |x| x == "der") {
let key = if key_path.extension().is_some_and(|x| x == "der") {
PrivateKeyDer::Pkcs8(PrivatePkcs8KeyDer::from(key))
} else {
rustls_pemfile::private_key(&mut &*key)
.context("malformed PKCS #1 private key")?
.ok_or_else(|| anyhow::Error::msg("no private keys found"))?
};
let cert_chain = fs::read(cert_path).context("failed to read certificate chain")?;
let cert_chain = if cert_path.extension().map_or(false, |x| x == "der") {
let cert_chain = if cert_path.extension().is_some_and(|x| x == "der") {
vec![CertificateDer::from(cert_chain)]
} else {
rustls_pemfile::certs(&mut &*cert_chain)
Expand Down Expand Up @@ -140,7 +140,7 @@ async fn run(options: Opt) -> Result<()> {
while let Some(conn) = endpoint.accept().await {
if options
.connection_limit
.map_or(false, |n| endpoint.open_connections() >= n)
.is_some_and(|n| endpoint.open_connections() >= n)
{
info!("refusing due to open connection limit");
conn.refuse();
Expand Down

0 comments on commit f8b8c50

Please sign in to comment.