diff --git a/quinn-proto/src/cid_generator.rs b/quinn-proto/src/cid_generator.rs index 1ed6d8999..583ff7611 100644 --- a/quinn-proto/src/cid_generator.rs +++ b/quinn-proto/src/cid_generator.rs @@ -46,7 +46,7 @@ impl RandomConnectionIdGenerator { debug_assert!(cid_len <= MAX_CID_SIZE); Self { cid_len, - ..RandomConnectionIdGenerator::default() + ..Self::default() } } diff --git a/quinn-proto/src/coding.rs b/quinn-proto/src/coding.rs index a9b8e67b6..a9c6adcd1 100644 --- a/quinn-proto/src/coding.rs +++ b/quinn-proto/src/coding.rs @@ -17,7 +17,7 @@ pub trait Codec: Sized { } impl Codec for u8 { - fn decode(buf: &mut B) -> Result { + fn decode(buf: &mut B) -> Result { if buf.remaining() < 1 { return Err(UnexpectedEnd); } @@ -29,7 +29,7 @@ impl Codec for u8 { } impl Codec for u16 { - fn decode(buf: &mut B) -> Result { + fn decode(buf: &mut B) -> Result { if buf.remaining() < 2 { return Err(UnexpectedEnd); } @@ -41,7 +41,7 @@ impl Codec for u16 { } impl Codec for u32 { - fn decode(buf: &mut B) -> Result { + fn decode(buf: &mut B) -> Result { if buf.remaining() < 4 { return Err(UnexpectedEnd); } @@ -53,7 +53,7 @@ impl Codec for u32 { } impl Codec for u64 { - fn decode(buf: &mut B) -> Result { + fn decode(buf: &mut B) -> Result { if buf.remaining() < 8 { return Err(UnexpectedEnd); } @@ -65,7 +65,7 @@ impl Codec for u64 { } impl Codec for Ipv4Addr { - fn decode(buf: &mut B) -> Result { + fn decode(buf: &mut B) -> Result { if buf.remaining() < 4 { return Err(UnexpectedEnd); } @@ -79,7 +79,7 @@ impl Codec for Ipv4Addr { } impl Codec for Ipv6Addr { - fn decode(buf: &mut B) -> Result { + fn decode(buf: &mut B) -> Result { if buf.remaining() < 16 { return Err(UnexpectedEnd); } diff --git a/quinn-proto/src/config.rs b/quinn-proto/src/config.rs index f1e99bdf4..a3097573a 100644 --- a/quinn-proto/src/config.rs +++ b/quinn-proto/src/config.rs @@ -283,7 +283,7 @@ impl Default for TransportConfig { // stalls const STREAM_RWND: u32 = MAX_STREAM_BANDWIDTH / 1000 * EXPECTED_RTT; - TransportConfig { + Self { max_concurrent_bidi_streams: 100u32.into(), max_concurrent_uni_streams: 100u32.into(), max_idle_timeout: Some(VarInt(10_000)), @@ -801,13 +801,13 @@ pub enum ConfigError { impl From for ConfigError { fn from(_: TryFromIntError) -> Self { - ConfigError::OutOfBounds + Self::OutOfBounds } } impl From for ConfigError { fn from(_: VarIntBoundsExceeded) -> Self { - ConfigError::OutOfBounds + Self::OutOfBounds } } diff --git a/quinn-proto/src/congestion/bbr/bw_estimation.rs b/quinn-proto/src/congestion/bbr/bw_estimation.rs index f7eb4faa0..7bb1cdb8d 100644 --- a/quinn-proto/src/congestion/bbr/bw_estimation.rs +++ b/quinn-proto/src/congestion/bbr/bw_estimation.rs @@ -44,7 +44,7 @@ impl BandwidthEstimation { }; let send_rate = if self.sent_time > prev_sent_time { - BandwidthEstimation::bw_from_delta( + Self::bw_from_delta( self.total_sent - self.prev_total_sent, self.sent_time - prev_sent_time, ) @@ -54,7 +54,7 @@ impl BandwidthEstimation { }; let ack_rate = match self.prev_acked_time { - Some(prev_acked_time) => BandwidthEstimation::bw_from_delta( + Some(prev_acked_time) => Self::bw_from_delta( self.total_acked - self.prev_total_acked, now - prev_acked_time, ) @@ -93,7 +93,7 @@ impl BandwidthEstimation { impl Default for BandwidthEstimation { fn default() -> Self { - BandwidthEstimation { + Self { total_acked: 0, prev_total_acked: 0, acked_time: None, diff --git a/quinn-proto/src/congestion/bbr/mod.rs b/quinn-proto/src/congestion/bbr/mod.rs index feb9131de..93062bf4b 100644 --- a/quinn-proto/src/congestion/bbr/mod.rs +++ b/quinn-proto/src/congestion/bbr/mod.rs @@ -609,7 +609,7 @@ enum RecoveryState { impl RecoveryState { pub fn in_recovery(&self) -> bool { - !matches!(self, RecoveryState::NotInRecovery) + !matches!(self, Self::NotInRecovery) } } diff --git a/quinn-proto/src/connection/assembler.rs b/quinn-proto/src/connection/assembler.rs index 48d6cbaa8..4e918583a 100644 --- a/quinn-proto/src/connection/assembler.rs +++ b/quinn-proto/src/connection/assembler.rs @@ -228,7 +228,7 @@ pub struct Chunk { impl Chunk { fn new(offset: u64, bytes: Bytes) -> Self { - Chunk { offset, bytes } + Self { offset, bytes } } } @@ -290,7 +290,7 @@ impl Buffer { impl Ord for Buffer { // Invert ordering based on offset (max-heap, min offset first), // prioritize longer chunks at the same offset. - fn cmp(&self, other: &Buffer) -> Ordering { + fn cmp(&self, other: &Self) -> Ordering { self.offset .cmp(&other.offset) .reverse() @@ -299,13 +299,13 @@ impl Ord for Buffer { } impl PartialOrd for Buffer { - fn partial_cmp(&self, other: &Buffer) -> Option { + fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } } impl PartialEq for Buffer { - fn eq(&self, other: &Buffer) -> bool { + fn eq(&self, other: &Self) -> bool { (self.offset, self.bytes.len()) == (other.offset, other.bytes.len()) } } @@ -322,13 +322,13 @@ enum State { impl State { fn is_ordered(&self) -> bool { - matches!(self, State::Ordered) + matches!(self, Self::Ordered) } } impl Default for State { fn default() -> Self { - State::Ordered + Self::Ordered } } diff --git a/quinn-proto/src/connection/cid_state.rs b/quinn-proto/src/connection/cid_state.rs index 873c9cbb5..d3e6e69bc 100644 --- a/quinn-proto/src/connection/cid_state.rs +++ b/quinn-proto/src/connection/cid_state.rs @@ -32,7 +32,7 @@ impl CidState { let mut active_seq = FxHashSet::default(); // Add sequence number of CID used in handshaking into tracking set active_seq.insert(0); - let mut this = CidState { + let mut this = Self { retire_timestamp: VecDeque::new(), issued: 1, // One CID is already supplied during handshaking active_seq, diff --git a/quinn-proto/src/connection/mod.rs b/quinn-proto/src/connection/mod.rs index 492b273e8..5f24d3e43 100644 --- a/quinn-proto/src/connection/mod.rs +++ b/quinn-proto/src/connection/mod.rs @@ -3284,15 +3284,15 @@ pub enum ConnectionError { impl From for ConnectionError { fn from(x: Close) -> Self { match x { - Close::Connection(reason) => ConnectionError::ConnectionClosed(reason), - Close::Application(reason) => ConnectionError::ApplicationClosed(reason), + Close::Connection(reason) => Self::ConnectionClosed(reason), + Close::Application(reason) => Self::ApplicationClosed(reason), } } } // For compatibility with API consumers impl From for io::Error { - fn from(x: ConnectionError) -> io::Error { + fn from(x: ConnectionError) -> Self { use self::ConnectionError::*; let kind = match x { TimedOut => io::ErrorKind::TimedOut, @@ -3300,7 +3300,7 @@ impl From for io::Error { ApplicationClosed(_) | ConnectionClosed(_) => io::ErrorKind::ConnectionAborted, TransportError(_) | VersionMismatch | LocallyClosed => io::ErrorKind::Other, }; - io::Error::new(kind, x) + Self::new(kind, x) } } @@ -3316,25 +3316,25 @@ pub enum State { impl State { fn closed>(reason: R) -> Self { - State::Closed(state::Closed { + Self::Closed(state::Closed { reason: reason.into(), }) } fn is_handshake(&self) -> bool { - matches!(*self, State::Handshake(_)) + matches!(*self, Self::Handshake(_)) } fn is_established(&self) -> bool { - matches!(*self, State::Established) + matches!(*self, Self::Established) } fn is_closed(&self) -> bool { - matches!(*self, State::Closed(_) | State::Draining | State::Drained) + matches!(*self, Self::Closed(_) | Self::Draining | Self::Drained) } fn is_drained(&self) -> bool { - matches!(*self, State::Drained) + matches!(*self, Self::Drained) } } diff --git a/quinn-proto/src/connection/packet_builder.rs b/quinn-proto/src/connection/packet_builder.rs index 042376342..b265b82f0 100644 --- a/quinn-proto/src/connection/packet_builder.rs +++ b/quinn-proto/src/connection/packet_builder.rs @@ -38,7 +38,7 @@ impl PacketBuilder { ack_eliciting: bool, conn: &mut Connection, version: u32, - ) -> Option { + ) -> Option { // Initiate key update if we're approaching the confidentiality limit let confidentiality_limit = conn.spaces[space_id] .crypto @@ -142,7 +142,7 @@ impl PacketBuilder { ); let max_size = buffer_capacity - partial_encode.start - partial_encode.header_len - tag_len; - Some(PacketBuilder { + Some(Self { datagram_start, space: space_id, partial_encode, @@ -210,11 +210,7 @@ impl PacketBuilder { } /// Encrypt packet, returning the length of the packet and whether padding was added - pub fn finish( - self: PacketBuilder, - conn: &mut Connection, - buffer: &mut Vec, - ) -> (usize, bool) { + pub fn finish(self, conn: &mut Connection, buffer: &mut Vec) -> (usize, bool) { let pad = buffer.len() < self.min_size; if pad { trace!("PADDING * {}", self.min_size - buffer.len()); diff --git a/quinn-proto/src/connection/paths.rs b/quinn-proto/src/connection/paths.rs index 03aba5243..94ca0cb0c 100644 --- a/quinn-proto/src/connection/paths.rs +++ b/quinn-proto/src/connection/paths.rs @@ -43,7 +43,7 @@ impl PathData { now: Instant, validated: bool, ) -> Self { - PathData { + Self { remote, rtt: RttEstimator::new(initial_rtt), sending_ecn: true, @@ -73,10 +73,10 @@ impl PathData { } } - pub fn from_previous(remote: SocketAddr, prev: &PathData, now: Instant) -> Self { + pub fn from_previous(remote: SocketAddr, prev: &Self, now: Instant) -> Self { let congestion = prev.congestion.clone_box(); let smoothed_rtt = prev.rtt.get(); - PathData { + Self { remote, rtt: prev.rtt, pacing: Pacer::new(smoothed_rtt, congestion.window(), prev.current_mtu(), now), diff --git a/quinn-proto/src/connection/spaces.rs b/quinn-proto/src/connection/spaces.rs index 2929eb20e..0b1189f4b 100644 --- a/quinn-proto/src/connection/spaces.rs +++ b/quinn-proto/src/connection/spaces.rs @@ -280,12 +280,12 @@ impl ::std::ops::BitOrAssign for Retransmits { } } -impl ::std::iter::FromIterator for Retransmits { +impl ::std::iter::FromIterator for Retransmits { fn from_iter(iter: T) -> Self where - T: IntoIterator, + T: IntoIterator, { - let mut result = Retransmits::default(); + let mut result = Self::default(); for packet in iter { result |= packet; } diff --git a/quinn-proto/src/connection/streams/recv.rs b/quinn-proto/src/connection/streams/recv.rs index a037ad5be..f04fa51af 100644 --- a/quinn-proto/src/connection/streams/recv.rs +++ b/quinn-proto/src/connection/streams/recv.rs @@ -369,7 +369,7 @@ pub enum ReadableError { impl From for ReadableError { fn from(_: IllegalOrderedRead) -> Self { - ReadableError::IllegalOrderedRead + Self::IllegalOrderedRead } } @@ -381,6 +381,6 @@ enum RecvState { impl Default for RecvState { fn default() -> Self { - RecvState::Recv { size: None } + Self::Recv { size: None } } } diff --git a/quinn-proto/src/connection/timer.rs b/quinn-proto/src/connection/timer.rs index 2b8b89e5e..bf41f6987 100644 --- a/quinn-proto/src/connection/timer.rs +++ b/quinn-proto/src/connection/timer.rs @@ -22,14 +22,14 @@ pub(crate) enum Timer { impl Timer { pub(crate) const VALUES: [Self; 8] = [ - Timer::LossDetection, - Timer::Idle, - Timer::Close, - Timer::KeyDiscard, - Timer::PathValidation, - Timer::KeepAlive, - Timer::Pacing, - Timer::PushNewCid, + Self::LossDetection, + Self::Idle, + Self::Close, + Self::KeyDiscard, + Self::PathValidation, + Self::KeepAlive, + Self::Pacing, + Self::PushNewCid, ]; } diff --git a/quinn-proto/src/crypto.rs b/quinn-proto/src/crypto.rs index ad15b5977..3c2cb5c04 100644 --- a/quinn-proto/src/crypto.rs +++ b/quinn-proto/src/crypto.rs @@ -219,6 +219,6 @@ pub struct UnsupportedVersion; impl From for ConnectError { fn from(_: UnsupportedVersion) -> Self { - ConnectError::UnsupportedVersion + Self::UnsupportedVersion } } diff --git a/quinn-proto/src/crypto/ring.rs b/quinn-proto/src/crypto/ring.rs index 8d7f417a2..48561f451 100644 --- a/quinn-proto/src/crypto/ring.rs +++ b/quinn-proto/src/crypto/ring.rs @@ -49,6 +49,6 @@ impl crypto::AeadKey for aead::LessSafeKey { impl From for CryptoError { fn from(_: ring::error::Unspecified) -> Self { - CryptoError + Self } } diff --git a/quinn-proto/src/crypto/rustls.rs b/quinn-proto/src/crypto/rustls.rs index 936cb7d56..7d325508a 100644 --- a/quinn-proto/src/crypto/rustls.rs +++ b/quinn-proto/src/crypto/rustls.rs @@ -19,8 +19,8 @@ use crate::{ impl From for rustls::Side { fn from(s: Side) -> Self { match s { - Side::Client => rustls::Side::Client, - Side::Server => rustls::Side::Server, + Side::Client => Self::Client, + Side::Server => Self::Server, } } } diff --git a/quinn-proto/src/endpoint.rs b/quinn-proto/src/endpoint.rs index 72046bbda..9f9e34bf0 100644 --- a/quinn-proto/src/endpoint.rs +++ b/quinn-proto/src/endpoint.rs @@ -778,7 +778,7 @@ pub(crate) struct ConnectionMeta { pub struct ConnectionHandle(pub usize); impl From for usize { - fn from(x: ConnectionHandle) -> usize { + fn from(x: ConnectionHandle) -> Self { x.0 } } diff --git a/quinn-proto/src/frame.rs b/quinn-proto/src/frame.rs index d8cdf45fd..0c2633fe4 100644 --- a/quinn-proto/src/frame.rs +++ b/quinn-proto/src/frame.rs @@ -40,7 +40,7 @@ impl Type { impl coding::Codec for Type { fn decode(buf: &mut B) -> coding::Result { - Ok(Type(buf.get_var()?)) + Ok(Self(buf.get_var()?)) } fn encode(&self, buf: &mut B) { buf.write_var(self.0); @@ -203,7 +203,7 @@ impl Frame { } pub fn is_ack_eliciting(&self) -> bool { - !matches!(*self, Frame::Ack(_) | Frame::Padding | Frame::Close(_)) + !matches!(*self, Self::Ack(_) | Self::Padding | Self::Close(_)) } } @@ -216,25 +216,25 @@ pub enum Close { impl Close { pub(crate) fn encode(&self, out: &mut W, max_len: usize) { match *self { - Close::Connection(ref x) => x.encode(out, max_len), - Close::Application(ref x) => x.encode(out, max_len), + Self::Connection(ref x) => x.encode(out, max_len), + Self::Application(ref x) => x.encode(out, max_len), } } } impl From for Close { fn from(x: TransportError) -> Self { - Close::Connection(x.into()) + Self::Connection(x.into()) } } impl From for Close { fn from(x: ConnectionClose) -> Self { - Close::Connection(x) + Self::Connection(x) } } impl From for Close { fn from(x: ApplicationClose) -> Self { - Close::Application(x) + Self::Application(x) } } @@ -262,7 +262,7 @@ impl fmt::Display for ConnectionClose { impl From for ConnectionClose { fn from(x: TransportError) -> Self { - ConnectionClose { + Self { error_code: x.code, frame_type: x.frame, reason: x.reason.into(), @@ -464,7 +464,7 @@ pub struct StreamMeta { // This manual implementation exists because `Default` is not implemented for `StreamId` impl Default for StreamMeta { fn default() -> Self { - StreamMeta { + Self { id: StreamId(0), offsets: 0..0, fin: false, @@ -540,13 +540,13 @@ impl IterErr { impl From for IterErr { fn from(_: UnexpectedEnd) -> Self { - IterErr::UnexpectedEnd + Self::UnexpectedEnd } } impl Iter { pub fn new(payload: Bytes) -> Self { - Iter { + Self { bytes: io::Cursor::new(payload), last_ty: None, } diff --git a/quinn-proto/src/lib.rs b/quinn-proto/src/lib.rs index 6de9281dc..2c5d29387 100644 --- a/quinn-proto/src/lib.rs +++ b/quinn-proto/src/lib.rs @@ -17,6 +17,7 @@ // Fixes welcome: #![allow(clippy::cognitive_complexity)] #![allow(clippy::too_many_arguments)] +#![warn(clippy::use_self)] use std::{ fmt, @@ -92,12 +93,12 @@ pub mod fuzzing { impl<'arbitrary> Arbitrary<'arbitrary> for TransportParameters { fn arbitrary(u: &mut Unstructured<'arbitrary>) -> Result { - Ok(TransportParameters { + Ok(Self { initial_max_streams_bidi: u.arbitrary()?, initial_max_streams_uni: u.arbitrary()?, ack_delay_exponent: u.arbitrary()?, max_udp_payload_size: u.arbitrary()?, - ..TransportParameters::default() + ..Self::default() }) } } @@ -115,7 +116,7 @@ pub mod fuzzing { let bytes: Vec = Vec::arbitrary(u)?; let mut buf = BytesMut::new(); buf.put_slice(&bytes[..]); - Ok(PacketParams { + Ok(Self { local_cid_len, buf, grease_quic_bit: bool::arbitrary(u)?, @@ -149,22 +150,22 @@ impl Side { #[inline] /// Shorthand for `self == Side::Client` pub fn is_client(self) -> bool { - self == Side::Client + self == Self::Client } #[inline] /// Shorthand for `self == Side::Server` pub fn is_server(self) -> bool { - self == Side::Server + self == Self::Server } } impl ops::Not for Side { - type Output = Side; - fn not(self) -> Side { + type Output = Self; + fn not(self) -> Self { match self { - Side::Client => Side::Server, - Side::Server => Side::Client, + Self::Client => Self::Server, + Self::Server => Self::Client, } } } @@ -181,7 +182,7 @@ pub enum Dir { impl Dir { fn iter() -> impl Iterator { - [Dir::Bi, Dir::Uni].iter().cloned() + [Self::Bi, Self::Uni].iter().cloned() } } @@ -223,7 +224,7 @@ impl fmt::Display for StreamId { impl StreamId { /// Create a new StreamId pub fn new(initiator: Side, dir: Dir, index: u64) -> Self { - StreamId(index << 2 | (dir as u64) << 1 | initiator as u64) + Self(index << 2 | (dir as u64) << 1 | initiator as u64) } /// Which side of a connection initiated the stream pub fn initiator(self) -> Side { @@ -248,8 +249,8 @@ impl StreamId { } impl From for VarInt { - fn from(x: StreamId) -> VarInt { - unsafe { VarInt::from_u64_unchecked(x.0) } + fn from(x: StreamId) -> Self { + unsafe { Self::from_u64_unchecked(x.0) } } } @@ -260,8 +261,8 @@ impl From for StreamId { } impl coding::Codec for StreamId { - fn decode(buf: &mut B) -> coding::Result { - VarInt::decode(buf).map(|x| StreamId(x.into_inner())) + fn decode(buf: &mut B) -> coding::Result { + VarInt::decode(buf).map(|x| Self(x.into_inner())) } fn encode(&self, buf: &mut B) { VarInt::from_u64(self.0).unwrap().encode(buf); diff --git a/quinn-proto/src/packet.rs b/quinn-proto/src/packet.rs index 11d929f15..d37762b9e 100644 --- a/quinn-proto/src/packet.rs +++ b/quinn-proto/src/packet.rs @@ -365,10 +365,7 @@ impl Header { /// Whether the packet is encrypted on the wire pub(crate) fn is_protected(&self) -> bool { - !matches!( - *self, - Header::Retry { .. } | Header::VersionNegotiate { .. } - ) + !matches!(*self, Self::Retry { .. } | Self::VersionNegotiate { .. }) } pub(crate) fn number(&self) -> Option { @@ -401,13 +398,13 @@ impl Header { pub(crate) fn key_phase(&self) -> bool { match *self { - Header::Short { key_phase, .. } => key_phase, + Self::Short { key_phase, .. } => key_phase, _ => false, } } pub(crate) fn is_short(&self) -> bool { - matches!(*self, Header::Short { .. }) + matches!(*self, Self::Short { .. }) } pub(crate) fn is_1rtt(&self) -> bool { @@ -417,7 +414,7 @@ impl Header { pub(crate) fn is_0rtt(&self) -> bool { matches!( *self, - Header::Long { + Self::Long { ty: LongType::ZeroRtt, .. } @@ -450,7 +447,7 @@ impl PartialEncode { header_crypto: &dyn crypto::HeaderKey, crypto: Option<(u64, &dyn crypto::PacketKey)>, ) { - let PartialEncode { header_len, pn, .. } = self; + let Self { header_len, pn, .. } = self; let (pn_len, write_len) = match pn { Some((pn_len, write_len)) => (pn_len, write_len), None => return, @@ -545,7 +542,7 @@ impl PlainHeader { return Err(PacketDecodeError::InvalidHeader("cid out of bounds")); } - Ok(PlainHeader::Short { + Ok(Self::Short { spin, dst_cid: ConnectionId::from_buf(buf, local_cid_len), }) @@ -560,7 +557,7 @@ impl PlainHeader { // TODO: Support long CIDs for compatibility with future QUIC versions if version == 0 { let random = first & !LONG_HEADER_FORM; - return Ok(PlainHeader::VersionNegotiate { + return Ok(Self::VersionNegotiate { random, dst_cid, src_cid, @@ -585,7 +582,7 @@ impl PlainHeader { buf.advance(token_len); let len = buf.get_var()?; - Ok(PlainHeader::Initial { + Ok(Self::Initial { dst_cid, src_cid, token_pos: token_start..token_start + token_len, @@ -593,12 +590,12 @@ impl PlainHeader { version, }) } - LongHeaderType::Retry => Ok(PlainHeader::Retry { + LongHeaderType::Retry => Ok(Self::Retry { dst_cid, src_cid, version, }), - LongHeaderType::Standard(ty) => Ok(PlainHeader::Long { + LongHeaderType::Standard(ty) => Ok(Self::Long { ty, dst_cid, src_cid, @@ -623,13 +620,13 @@ impl PacketNumber { pub(crate) fn new(n: u64, largest_acked: u64) -> Self { let range = (n - largest_acked) * 2; if range < 1 << 8 { - PacketNumber::U8(n as u8) + Self::U8(n as u8) } else if range < 1 << 16 { - PacketNumber::U16(n as u16) + Self::U16(n as u16) } else if range < 1 << 24 { - PacketNumber::U24(n as u32) + Self::U24(n as u32) } else if range < 1 << 32 { - PacketNumber::U32(n as u32) + Self::U32(n as u32) } else { panic!("packet number too large to encode") } @@ -655,7 +652,7 @@ impl PacketNumber { } } - pub(crate) fn decode(len: usize, r: &mut R) -> Result { + pub(crate) fn decode(len: usize, r: &mut R) -> Result { use self::PacketNumber::*; let pn = match len { 1 => U8(r.get()?), @@ -736,7 +733,7 @@ impl LongHeaderType { } impl From for u8 { - fn from(ty: LongHeaderType) -> u8 { + fn from(ty: LongHeaderType) -> Self { use self::{LongHeaderType::*, LongType::*}; match ty { Initial => LONG_HEADER_FORM | FIXED_BIT, @@ -768,7 +765,7 @@ pub enum PacketDecodeError { impl From for PacketDecodeError { fn from(_: coding::UnexpectedEnd) -> Self { - PacketDecodeError::InvalidHeader("unexpected end of packet") + Self::InvalidHeader("unexpected end of packet") } } @@ -791,9 +788,7 @@ pub enum SpaceId { impl SpaceId { pub fn iter() -> impl Iterator { - [SpaceId::Initial, SpaceId::Handshake, SpaceId::Data] - .iter() - .cloned() + [Self::Initial, Self::Handshake, Self::Data].iter().cloned() } } diff --git a/quinn-proto/src/range_set/array_range_set.rs b/quinn-proto/src/range_set/array_range_set.rs index 54605acd1..f618a73e7 100644 --- a/quinn-proto/src/range_set/array_range_set.rs +++ b/quinn-proto/src/range_set/array_range_set.rs @@ -68,7 +68,7 @@ impl ArrayRangeSet { false } - pub fn subtract(&mut self, other: &ArrayRangeSet) { + pub fn subtract(&mut self, other: &Self) { // TODO: This can potentially be made more efficient, since the we know // individual ranges are not overlapping, and the next range must start // after the last one finished diff --git a/quinn-proto/src/range_set/btree_range_set.rs b/quinn-proto/src/range_set/btree_range_set.rs index 4c82fc433..e4babd298 100644 --- a/quinn-proto/src/range_set/btree_range_set.rs +++ b/quinn-proto/src/range_set/btree_range_set.rs @@ -161,13 +161,13 @@ impl RangeSet { } } - pub fn add(&mut self, other: &RangeSet) { + pub fn add(&mut self, other: &Self) { for (&start, &end) in &other.0 { self.insert(start..end); } } - pub fn subtract(&mut self, other: &RangeSet) { + pub fn subtract(&mut self, other: &Self) { for (&start, &end) in &other.0 { self.remove(start..end); } diff --git a/quinn-proto/src/tests/util.rs b/quinn-proto/src/tests/util.rs index 446c47930..e0d67dfbd 100644 --- a/quinn-proto/src/tests/util.rs +++ b/quinn-proto/src/tests/util.rs @@ -38,7 +38,7 @@ impl Pair { let server = Endpoint::new(endpoint_config.clone(), Some(Arc::new(server_config))); let client = Endpoint::new(endpoint_config, None); - Pair::new_from_endpoint(client, server) + Self::new_from_endpoint(client, server) } pub fn new_from_endpoint(client: Endpoint, server: Endpoint) -> Self { @@ -248,7 +248,7 @@ impl Pair { impl Default for Pair { fn default() -> Self { - Pair::new(Default::default(), server_config()) + Self::new(Default::default(), server_config()) } } diff --git a/quinn-proto/src/token.rs b/quinn-proto/src/token.rs index 81a0c8cd5..fa424e666 100644 --- a/quinn-proto/src/token.rs +++ b/quinn-proto/src/token.rs @@ -122,7 +122,7 @@ impl ResetToken { } impl PartialEq for ResetToken { - fn eq(&self, other: &ResetToken) -> bool { + fn eq(&self, other: &Self) -> bool { crate::constant_time::eq(&self.0, &other.0) } } diff --git a/quinn-proto/src/transport_error.rs b/quinn-proto/src/transport_error.rs index 63e06a1ee..5007f7713 100644 --- a/quinn-proto/src/transport_error.rs +++ b/quinn-proto/src/transport_error.rs @@ -50,13 +50,13 @@ pub struct Code(u64); impl Code { /// Create QUIC error code from TLS alert code pub fn crypto(code: u8) -> Self { - Code(0x100 | u64::from(code)) + Self(0x100 | u64::from(code)) } } impl coding::Codec for Code { fn decode(buf: &mut B) -> coding::Result { - Ok(Code(buf.get_var()?)) + Ok(Self(buf.get_var()?)) } fn encode(&self, buf: &mut B) { buf.write_var(self.0) @@ -64,7 +64,7 @@ impl coding::Codec for Code { } impl From for u64 { - fn from(x: Code) -> u64 { + fn from(x: Code) -> Self { x.0 } } diff --git a/quinn-proto/src/transport_parameters.rs b/quinn-proto/src/transport_parameters.rs index a3ca0afa3..c9451c1e9 100644 --- a/quinn-proto/src/transport_parameters.rs +++ b/quinn-proto/src/transport_parameters.rs @@ -125,7 +125,7 @@ impl TransportParameters { initial_src_cid: ConnectionId, server_config: Option<&ServerConfig>, ) -> Self { - TransportParameters { + Self { initial_src_cid: Some(initial_src_cid), initial_max_streams_bidi: config.max_concurrent_bidi_streams, initial_max_streams_uni: config.max_concurrent_uni_streams, @@ -152,10 +152,7 @@ impl TransportParameters { /// Check that these parameters are legal when resuming from /// certain cached parameters - pub(crate) fn validate_resumption_from( - &self, - cached: &TransportParameters, - ) -> Result<(), TransportError> { + pub(crate) fn validate_resumption_from(&self, cached: &Self) -> Result<(), TransportError> { if cached.active_connection_id_limit > self.active_connection_id_limit || cached.initial_max_data > self.initial_max_data || cached.initial_max_stream_data_bidi_local > self.initial_max_stream_data_bidi_local @@ -261,15 +258,15 @@ pub enum Error { impl From for TransportError { fn from(e: Error) -> Self { match e { - Error::IllegalValue => TransportError::TRANSPORT_PARAMETER_ERROR("illegal value"), - Error::Malformed => TransportError::TRANSPORT_PARAMETER_ERROR("malformed"), + Error::IllegalValue => Self::TRANSPORT_PARAMETER_ERROR("illegal value"), + Error::Malformed => Self::TRANSPORT_PARAMETER_ERROR("malformed"), } } } impl From for Error { fn from(_: UnexpectedEnd) -> Self { - Error::Malformed + Self::Malformed } } @@ -337,7 +334,7 @@ impl TransportParameters { /// Decode `TransportParameters` from buffer pub fn read(side: Side, r: &mut R) -> Result { // Initialize to protocol-specified defaults - let mut params = TransportParameters::default(); + let mut params = Self::default(); // State to check for duplicate transport parameters. macro_rules! param_state { diff --git a/quinn-proto/src/varint.rs b/quinn-proto/src/varint.rs index 69d21f3c2..9d2e8f45d 100644 --- a/quinn-proto/src/varint.rs +++ b/quinn-proto/src/varint.rs @@ -18,19 +18,19 @@ pub struct VarInt(pub(crate) u64); impl VarInt { /// The largest representable value - pub const MAX: VarInt = VarInt((1 << 62) - 1); + pub const MAX: Self = Self((1 << 62) - 1); /// The largest encoded value length pub const MAX_SIZE: usize = 8; /// Construct a `VarInt` infallibly pub const fn from_u32(x: u32) -> Self { - VarInt(x as u64) + Self(x as u64) } /// Succeeds iff `x` < 2^62 pub fn from_u64(x: u64) -> Result { if x < 2u64.pow(62) { - Ok(VarInt(x)) + Ok(Self(x)) } else { Err(VarIntBoundsExceeded) } @@ -42,7 +42,7 @@ impl VarInt { /// /// `x` must be less than 2^62. pub const unsafe fn from_u64_unchecked(x: u64) -> Self { - VarInt(x) + Self(x) } /// Extract the integer value @@ -68,26 +68,26 @@ impl VarInt { } impl From for u64 { - fn from(x: VarInt) -> u64 { + fn from(x: VarInt) -> Self { x.0 } } impl From for VarInt { fn from(x: u8) -> Self { - VarInt(x.into()) + Self(x.into()) } } impl From for VarInt { fn from(x: u16) -> Self { - VarInt(x.into()) + Self(x.into()) } } impl From for VarInt { fn from(x: u32) -> Self { - VarInt(x.into()) + Self(x.into()) } } @@ -95,7 +95,7 @@ impl std::convert::TryFrom for VarInt { type Error = VarIntBoundsExceeded; /// Succeeds iff `x` < 2^62 fn try_from(x: u64) -> Result { - VarInt::from_u64(x) + Self::from_u64(x) } } @@ -103,7 +103,7 @@ impl std::convert::TryFrom for VarInt { type Error = VarIntBoundsExceeded; /// Succeeds iff `x` < 2^62 fn try_from(x: u128) -> Result { - VarInt::from_u64(x.try_into().map_err(|_| VarIntBoundsExceeded)?) + Self::from_u64(x.try_into().map_err(|_| VarIntBoundsExceeded)?) } } @@ -111,7 +111,7 @@ impl std::convert::TryFrom for VarInt { type Error = VarIntBoundsExceeded; /// Succeeds iff `x` < 2^62 fn try_from(x: usize) -> Result { - VarInt::try_from(x as u64) + Self::try_from(x as u64) } } @@ -130,7 +130,7 @@ impl fmt::Display for VarInt { #[cfg(feature = "arbitrary")] impl<'arbitrary> Arbitrary<'arbitrary> for VarInt { fn arbitrary(u: &mut arbitrary::Unstructured<'arbitrary>) -> arbitrary::Result { - Ok(VarInt(u.int_in_range(0..=VarInt::MAX.0)?)) + Ok(Self(u.int_in_range(0..=Self::MAX.0)?)) } } @@ -173,7 +173,7 @@ impl Codec for VarInt { } _ => unreachable!(), }; - Ok(VarInt(x)) + Ok(Self(x)) } fn encode(&self, w: &mut B) { diff --git a/quinn-udp/src/lib.rs b/quinn-udp/src/lib.rs index 565cb1c7a..69d58dff4 100644 --- a/quinn-udp/src/lib.rs +++ b/quinn-udp/src/lib.rs @@ -1,4 +1,6 @@ //! Uniform interface to send/recv UDP packets with ECN information. +#![warn(clippy::use_self)] + #[cfg(unix)] use std::os::unix::io::AsRawFd; #[cfg(windows)] diff --git a/quinn/src/connection.rs b/quinn/src/connection.rs index 4fa5768c0..958719cc0 100644 --- a/quinn/src/connection.rs +++ b/quinn/src/connection.rs @@ -44,7 +44,7 @@ impl Connecting { conn_events: mpsc::UnboundedReceiver, udp_state: Arc, runtime: Arc, - ) -> Connecting { + ) -> Self { let (on_handshake_data_send, on_handshake_data_recv) = oneshot::channel(); let (on_connected_send, on_connected_recv) = oneshot::channel(); let conn = ConnectionRef::new( @@ -60,7 +60,7 @@ impl Connecting { runtime.spawn(Box::pin(ConnectionDriver(conn.clone()))); - Connecting { + Self { conn: Some(conn), connected: on_connected_recv, handshake_data_ready: Some(on_handshake_data_recv), @@ -1149,6 +1149,6 @@ pub struct UnknownStream { impl From for UnknownStream { fn from(_: proto::UnknownStream) -> Self { - UnknownStream { _private: () } + Self { _private: () } } } diff --git a/quinn/src/lib.rs b/quinn/src/lib.rs index 75c44b59a..2960634fc 100644 --- a/quinn/src/lib.rs +++ b/quinn/src/lib.rs @@ -38,6 +38,7 @@ //! with a domain name--then as with TLS, self-signed certificates can be used to provide //! encryption alone. #![warn(missing_docs)] +#![warn(clippy::use_self)] use std::time::Duration; diff --git a/quinn/src/recv_stream.rs b/quinn/src/recv_stream.rs index d433a18e8..3ef50162b 100644 --- a/quinn/src/recv_stream.rs +++ b/quinn/src/recv_stream.rs @@ -348,8 +348,8 @@ enum ReadStatus { impl From<(Option, Option)> for ReadStatus { fn from(status: (Option, Option)) -> Self { match status { - (read, None) => ReadStatus::Finished(read), - (read, Some(e)) => ReadStatus::Failed(read, e), + (read, None) => Self::Finished(read), + (read, Some(e)) => Self::Failed(read, e), } } } @@ -428,7 +428,7 @@ impl tokio::io::AsyncRead for RecvStream { cx: &mut Context<'_>, buf: &mut ReadBuf<'_>, ) -> Poll> { - ready!(RecvStream::poll_read(self.get_mut(), cx, buf))?; + ready!(Self::poll_read(self.get_mut(), cx, buf))?; Poll::Ready(Ok(())) } } @@ -484,8 +484,8 @@ pub enum ReadError { impl From for ReadError { fn from(e: ReadableError) -> Self { match e { - ReadableError::UnknownStream => ReadError::UnknownStream, - ReadableError::IllegalOrderedRead => ReadError::IllegalOrderedRead, + ReadableError::UnknownStream => Self::UnknownStream, + ReadableError::IllegalOrderedRead => Self::IllegalOrderedRead, } } } @@ -498,7 +498,7 @@ impl From for io::Error { ConnectionLost(_) | UnknownStream => io::ErrorKind::NotConnected, IllegalOrderedRead => io::ErrorKind::InvalidInput, }; - io::Error::new(kind, x) + Self::new(kind, x) } } diff --git a/quinn/src/runtime/tokio.rs b/quinn/src/runtime/tokio.rs index f696bf0e8..c92d840ec 100644 --- a/quinn/src/runtime/tokio.rs +++ b/quinn/src/runtime/tokio.rs @@ -37,7 +37,7 @@ impl Runtime for TokioRuntime { impl AsyncTimer for Sleep { fn reset(self: Pin<&mut Self>, t: Instant) { - Sleep::reset(self, t.into()) + Self::reset(self, t.into()) } fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<()> { Future::poll(self, cx) diff --git a/quinn/src/send_stream.rs b/quinn/src/send_stream.rs index 62c203973..b822c63d9 100644 --- a/quinn/src/send_stream.rs +++ b/quinn/src/send_stream.rs @@ -246,7 +246,7 @@ impl tokio::io::AsyncWrite for SendStream { cx: &mut Context<'_>, buf: &[u8], ) -> Poll> { - SendStream::execute_poll(self.get_mut(), cx, |stream| stream.write(buf)).map_err(Into::into) + Self::execute_poll(self.get_mut(), cx, |stream| stream.write(buf)).map_err(Into::into) } fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context) -> Poll> { @@ -471,6 +471,6 @@ impl From for io::Error { Stopped(_) | ZeroRttRejected => io::ErrorKind::ConnectionReset, ConnectionLost(_) | UnknownStream => io::ErrorKind::NotConnected, }; - io::Error::new(kind, x) + Self::new(kind, x) } }