From adc7ba917ba5c58a0835ba53c6e17656aa81192b Mon Sep 17 00:00:00 2001 From: Jou Ho <43765840+jouho@users.noreply.github.com> Date: Fri, 10 Jan 2025 12:07:54 -0800 Subject: [PATCH] build: address clippy issues from 1.84 (#2444) --- dc/s2n-quic-dc/src/fixed_map.rs | 2 +- dc/s2n-quic-dc/src/packet/stream/decoder.rs | 2 +- dc/s2n-quic-dc/src/stream/send/application/state.rs | 6 +++--- quic/s2n-quic-core/src/buffer/reader.rs | 4 ++-- quic/s2n-quic-core/src/buffer/reassembler.rs | 5 ++--- quic/s2n-quic-core/src/buffer/reassembler/reader.rs | 2 +- quic/s2n-quic-core/src/recovery/bandwidth/estimator.rs | 2 +- quic/s2n-quic-core/src/recovery/bbr/probe_bw.rs | 2 +- quic/s2n-quic-core/src/recovery/bbr/windowed_filter.rs | 5 ++--- quic/s2n-quic-core/src/recovery/persistent_congestion.rs | 2 +- quic/s2n-quic-core/src/stream/testing.rs | 2 +- quic/s2n-quic-sim/src/stats.rs | 2 +- .../src/connection/local_id_registry.rs | 8 ++++---- .../s2n-quic-transport/src/connection/peer_id_registry.rs | 4 +--- quic/s2n-quic-transport/src/connection/transmission.rs | 5 ++--- quic/s2n-quic-transport/src/path/manager.rs | 6 +++--- quic/s2n-quic-transport/src/stream/contract.rs | 2 +- quic/s2n-quic-transport/src/stream/send_stream.rs | 2 +- quic/s2n-quic/src/client/providers.rs | 2 +- quic/s2n-quic/src/provider/address_token/default.rs | 2 +- quic/s2n-quic/src/server/providers.rs | 2 +- 21 files changed, 32 insertions(+), 37 deletions(-) diff --git a/dc/s2n-quic-dc/src/fixed_map.rs b/dc/s2n-quic-dc/src/fixed_map.rs index d4e98b40cd..77184f533f 100644 --- a/dc/s2n-quic-dc/src/fixed_map.rs +++ b/dc/s2n-quic-dc/src/fixed_map.rs @@ -204,7 +204,7 @@ where // Scan each value and check if our requested needle is present. let values = self.values.read(); for (value_idx, value) in values.iter().enumerate() { - if value.as_ref().map_or(false, |(k, _)| *k == *needle) { + if value.as_ref().is_some_and(|(k, _)| *k == *needle) { return Some(RwLockReadGuard::map(values, |values| { &values[value_idx].as_ref().unwrap().1 })); diff --git a/dc/s2n-quic-dc/src/packet/stream/decoder.rs b/dc/s2n-quic-dc/src/packet/stream/decoder.rs index bc74554bb1..59a45ba901 100644 --- a/dc/s2n-quic-dc/src/packet/stream/decoder.rs +++ b/dc/s2n-quic-dc/src/packet/stream/decoder.rs @@ -198,7 +198,7 @@ impl Packet<'_> { let len = VarInt::try_from(self.payload.len()).ok()?; offset.checked_sub(len) }) - .map_or(false, |v| *v == 0) + .is_some_and(|v| *v == 0) } #[inline] diff --git a/dc/s2n-quic-dc/src/stream/send/application/state.rs b/dc/s2n-quic-dc/src/stream/send/application/state.rs index 99ee74c7e0..6bfd08632a 100644 --- a/dc/s2n-quic-dc/src/stream/send/application/state.rs +++ b/dc/s2n-quic-dc/src/stream/send/application/state.rs @@ -115,9 +115,9 @@ impl State { let has_more_app_data = credits.initial_len > total_payload_len; - let included_fin = reader.final_offset().map_or(false, |fin| { - stream_offset.as_u64() + payload_len as u64 == fin.as_u64() - }); + let included_fin = reader + .final_offset() + .is_some_and(|fin| stream_offset.as_u64() + payload_len as u64 == fin.as_u64()); let time_sent = clock.get_time(); probes::on_transmit_stream( diff --git a/quic/s2n-quic-core/src/buffer/reader.rs b/quic/s2n-quic-core/src/buffer/reader.rs index 6db06fa251..3b8def4599 100644 --- a/quic/s2n-quic-core/src/buffer/reader.rs +++ b/quic/s2n-quic-core/src/buffer/reader.rs @@ -31,7 +31,7 @@ pub trait Reader: Storage { /// Returns `true` if the reader has the final offset buffered #[inline] fn has_buffered_fin(&self) -> bool { - self.final_offset().map_or(false, |fin| { + self.final_offset().is_some_and(|fin| { let buffered_end = self .current_offset() .as_u64() @@ -44,7 +44,7 @@ pub trait Reader: Storage { #[inline] fn is_consumed(&self) -> bool { self.final_offset() - .map_or(false, |fin| fin == self.current_offset()) + .is_some_and(|fin| fin == self.current_offset()) } /// Skips the data in the reader until `offset` is reached, or the reader storage is exhausted. diff --git a/quic/s2n-quic-core/src/buffer/reassembler.rs b/quic/s2n-quic-core/src/buffer/reassembler.rs index 28f1f60bfe..363d1dab66 100644 --- a/quic/s2n-quic-core/src/buffer/reassembler.rs +++ b/quic/s2n-quic-core/src/buffer/reassembler.rs @@ -127,14 +127,13 @@ impl Reassembler { #[inline] pub fn is_writing_complete(&self) -> bool { self.final_size() - .map_or(false, |len| self.total_received_len() == len) + .is_some_and(|len| self.total_received_len() == len) } /// Returns true if the buffer has completely been read and the final size is known #[inline] pub fn is_reading_complete(&self) -> bool { - self.final_size() - .map_or(false, |len| self.cursors.start_offset == len) + self.final_size() == Some(self.cursors.start_offset) } /// Returns the final size of the stream, if known diff --git a/quic/s2n-quic-core/src/buffer/reassembler/reader.rs b/quic/s2n-quic-core/src/buffer/reassembler/reader.rs index 0ad49194cb..d0d8c60478 100644 --- a/quic/s2n-quic-core/src/buffer/reassembler/reader.rs +++ b/quic/s2n-quic-core/src/buffer/reassembler/reader.rs @@ -40,7 +40,7 @@ impl Storage for Reassembler { ); // if we have a final size and this slot overlaps it then return the entire thing - let chunk = if self.cursors.final_size().map_or(false, |final_size| { + let chunk = if self.cursors.final_size().is_some_and(|final_size| { final_size <= slot.end_allocated() && watermark >= slot.buffered_len() }) { slot.consume() diff --git a/quic/s2n-quic-core/src/recovery/bandwidth/estimator.rs b/quic/s2n-quic-core/src/recovery/bandwidth/estimator.rs index a69e10d64b..47603432c1 100644 --- a/quic/s2n-quic-core/src/recovery/bandwidth/estimator.rs +++ b/quic/s2n-quic-core/src/recovery/bandwidth/estimator.rs @@ -347,7 +347,7 @@ impl Estimator { |app_limited_bytes| self.delivered_bytes > app_limited_bytes; if self .app_limited_delivered_bytes - .map_or(false, is_app_limited_period_over) + .is_some_and(is_app_limited_period_over) { // Clear app-limited field if bubble is ACKed and gone self.app_limited_delivered_bytes = None; diff --git a/quic/s2n-quic-core/src/recovery/bbr/probe_bw.rs b/quic/s2n-quic-core/src/recovery/bbr/probe_bw.rs index 70d1551f4c..c255978b67 100644 --- a/quic/s2n-quic-core/src/recovery/bbr/probe_bw.rs +++ b/quic/s2n-quic-core/src/recovery/bbr/probe_bw.rs @@ -297,7 +297,7 @@ impl State { //# return Now() > BBR.cycle_stamp + interval self.cycle_start_timestamp - .map_or(false, |cycle_stamp| now > cycle_stamp + interval) + .is_some_and(|cycle_stamp| now > cycle_stamp + interval) } /// Bandwidth probing can cause loss. To help coexistence with loss-based diff --git a/quic/s2n-quic-core/src/recovery/bbr/windowed_filter.rs b/quic/s2n-quic-core/src/recovery/bbr/windowed_filter.rs index 189c798b41..0d67703c04 100644 --- a/quic/s2n-quic-core/src/recovery/bbr/windowed_filter.rs +++ b/quic/s2n-quic-core/src/recovery/bbr/windowed_filter.rs @@ -84,9 +84,8 @@ impl< #[inline] fn window_expired(&self, now: TimeType) -> bool { - self.last_updated.map_or(false, |last_updated| { - now - last_updated >= self.window_length - }) + self.last_updated + .is_some_and(|last_updated| now - last_updated >= self.window_length) } } //= https://tools.ietf.org/id/draft-cardwell-iccrg-bbr-congestion-control-02#4.5.3.2 diff --git a/quic/s2n-quic-core/src/recovery/persistent_congestion.rs b/quic/s2n-quic-core/src/recovery/persistent_congestion.rs index b62b4ad210..8fef172d60 100644 --- a/quic/s2n-quic-core/src/recovery/persistent_congestion.rs +++ b/quic/s2n-quic-core/src/recovery/persistent_congestion.rs @@ -46,7 +46,7 @@ impl Calculator { //# potentially too few probes. ensure!(self .first_rtt_sample - .map_or(false, |ts| packet_info.time_sent >= ts)); + .is_some_and(|ts| packet_info.time_sent >= ts)); // Check that this lost packet was sent on the same path // diff --git a/quic/s2n-quic-core/src/stream/testing.rs b/quic/s2n-quic-core/src/stream/testing.rs index ca756548c5..e8a1c78bde 100644 --- a/quic/s2n-quic-core/src/stream/testing.rs +++ b/quic/s2n-quic-core/src/stream/testing.rs @@ -10,7 +10,7 @@ use bytes::Bytes; use bolero_generator::prelude::*; static DATA: Bytes = { - const INNER: [u8; DATA_LEN] = { + static INNER: [u8; DATA_LEN] = { let mut data = [0; DATA_LEN]; let mut idx = 0; while idx < DATA_LEN { diff --git a/quic/s2n-quic-sim/src/stats.rs b/quic/s2n-quic-sim/src/stats.rs index 8573cacd29..550728e823 100644 --- a/quic/s2n-quic-sim/src/stats.rs +++ b/quic/s2n-quic-sim/src/stats.rs @@ -744,7 +744,7 @@ impl Filter { pub fn apply(&self, params: &Parameters, conn: &Connection, conns: &[Connection]) -> bool { self.query .apply(params, conn, conns) - .map_or(false, |actual| (self.op)(actual, self.value)) + .is_some_and(|actual| (self.op)(actual, self.value)) } } diff --git a/quic/s2n-quic-transport/src/connection/local_id_registry.rs b/quic/s2n-quic-transport/src/connection/local_id_registry.rs index c2aea54e6f..fb8d43e923 100644 --- a/quic/s2n-quic-transport/src/connection/local_id_registry.rs +++ b/quic/s2n-quic-transport/src/connection/local_id_registry.rs @@ -116,9 +116,9 @@ impl LocalIdInfo { // Returns true if the connection ID should be moved to PendingRemoval fn is_retire_ready(&self, timestamp: Timestamp) -> bool { !self.is_retired() - && self.retirement_time.map_or(false, |retirement_time| { - retirement_time.has_elapsed(timestamp) - }) + && self + .retirement_time + .is_some_and(|retirement_time| retirement_time.has_elapsed(timestamp)) } // Returns true if the connection ID has been retired and is pending removal @@ -132,7 +132,7 @@ impl LocalIdInfo { // Returns true if the connection ID should no longer be used fn is_expired(&self, timestamp: Timestamp) -> bool { self.removal_time() - .map_or(false, |removal_time| removal_time.has_elapsed(timestamp)) + .is_some_and(|removal_time| removal_time.has_elapsed(timestamp)) } // The time this connection ID should be removed diff --git a/quic/s2n-quic-transport/src/connection/peer_id_registry.rs b/quic/s2n-quic-transport/src/connection/peer_id_registry.rs index 8c464c5c0e..9b45843819 100644 --- a/quic/s2n-quic-transport/src/connection/peer_id_registry.rs +++ b/quic/s2n-quic-transport/src/connection/peer_id_registry.rs @@ -107,9 +107,7 @@ impl PeerIdInfo { stateless_reset_token: &stateless_reset::Token, sequence_number: u32, ) -> Result { - let reset_token_is_equal = self - .stateless_reset_token - .map_or(false, |token| token == *stateless_reset_token); + let reset_token_is_equal = self.stateless_reset_token == Some(*stateless_reset_token); let sequence_number_is_equal = self.sequence_number == sequence_number; if self.id == *new_id { diff --git a/quic/s2n-quic-transport/src/connection/transmission.rs b/quic/s2n-quic-transport/src/connection/transmission.rs index d91b4e80a3..b1faad6b6f 100644 --- a/quic/s2n-quic-transport/src/connection/transmission.rs +++ b/quic/s2n-quic-transport/src/connection/transmission.rs @@ -445,7 +445,6 @@ fn has_transmission( transmission_interest_provider: Option<&P>, transmission_constraint: transmission::Constraint, ) -> bool { - transmission_interest_provider.map_or(false, |provider| { - provider.can_transmit(transmission_constraint) - }) + transmission_interest_provider + .is_some_and(|provider| provider.can_transmit(transmission_constraint)) } diff --git a/quic/s2n-quic-transport/src/path/manager.rs b/quic/s2n-quic-transport/src/path/manager.rs index 1997c47111..e2f901a11e 100644 --- a/quic/s2n-quic-transport/src/path/manager.rs +++ b/quic/s2n-quic-transport/src/path/manager.rs @@ -250,9 +250,9 @@ impl Manager { let valid_initial_received = self.valid_initial_received(); if let Some((id, path)) = self.path_mut(path_handle) { - let source_cid_changed = datagram.source_connection_id.map_or(false, |scid| { - scid != path.peer_connection_id && valid_initial_received - }); + let source_cid_changed = datagram + .source_connection_id + .is_some_and(|scid| scid != path.peer_connection_id && valid_initial_received); if source_cid_changed { //= https://www.rfc-editor.org/rfc/rfc9000#section-7.2 diff --git a/quic/s2n-quic-transport/src/stream/contract.rs b/quic/s2n-quic-transport/src/stream/contract.rs index ccf9eec911..3c3c6d3afa 100644 --- a/quic/s2n-quic-transport/src/stream/contract.rs +++ b/quic/s2n-quic-transport/src/stream/contract.rs @@ -107,7 +107,7 @@ pub mod tx { } // resetting takes priority - if self.reset.is_some() || response.map_or(false, |res| res.is_reset()) { + if self.reset.is_some() || response.is_ok_and(|res| res.is_reset()) { let response = response.expect("reset should never fail"); assert_eq!( diff --git a/quic/s2n-quic-transport/src/stream/send_stream.rs b/quic/s2n-quic-transport/src/stream/send_stream.rs index c336a0e514..a1ae695b2f 100644 --- a/quic/s2n-quic-transport/src/stream/send_stream.rs +++ b/quic/s2n-quic-transport/src/stream/send_stream.rs @@ -584,7 +584,7 @@ impl SendStream { .flow_controller_mut() .on_packet_ack(ack_set); - let should_flush = self.write_waiter.as_ref().map_or(false, |w| w.1); + let should_flush = self.write_waiter.as_ref().is_some_and(|w| w.1); let mut should_wake = false; self.data_sender .flow_controller_mut() diff --git a/quic/s2n-quic/src/client/providers.rs b/quic/s2n-quic/src/client/providers.rs index 88c7344d7d..75169ad6e2 100644 --- a/quic/s2n-quic/src/client/providers.rs +++ b/quic/s2n-quic/src/client/providers.rs @@ -106,7 +106,7 @@ impl< }; if connection_id .lifetime() - .map_or(false, |lifetime| !valid_lifetime(lifetime)) + .is_some_and(|lifetime| !valid_lifetime(lifetime)) { return Err(StartError::new(connection::id::Error::InvalidLifetime)); }; diff --git a/quic/s2n-quic/src/provider/address_token/default.rs b/quic/s2n-quic/src/provider/address_token/default.rs index d7eb23d743..723f8fa2e7 100644 --- a/quic/s2n-quic/src/provider/address_token/default.rs +++ b/quic/s2n-quic/src/provider/address_token/default.rs @@ -199,7 +199,7 @@ impl Format { if self.keys[token.header.key_id() as usize] .duplicate_filter .as_ref() - .map_or(false, |f| f.contains(token)) + .is_some_and(|f| f.contains(token)) { return None; } diff --git a/quic/s2n-quic/src/server/providers.rs b/quic/s2n-quic/src/server/providers.rs index 2cac7f260f..3b817821e2 100644 --- a/quic/s2n-quic/src/server/providers.rs +++ b/quic/s2n-quic/src/server/providers.rs @@ -118,7 +118,7 @@ impl< }; if connection_id .lifetime() - .map_or(false, |lifetime| !valid_lifetime(lifetime)) + .is_some_and(|lifetime| !valid_lifetime(lifetime)) { return Err(StartError::new(connection::id::Error::InvalidLifetime)); };