Skip to content

Commit

Permalink
Rust clippy updates (mozilla#1494)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinthomson authored Nov 20, 2023
1 parent 8a3aaa2 commit b0eb12a
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 41 deletions.
20 changes: 10 additions & 10 deletions neqo-common/src/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ impl<'a> Decoder<'a> {
/// # Panics
/// If the remaining quantity is less than `n`.
pub fn skip(&mut self, n: usize) {
assert!(self.remaining() >= n);
assert!(self.remaining() >= n, "insufficient data");
self.offset += n;
}

/// Skip helper that panics if `n` is `None` or not able to fit in `usize`.
fn skip_inner(&mut self, n: Option<u64>) {
self.skip(usize::try_from(n.unwrap()).unwrap());
self.skip(usize::try_from(n.expect("invalid length")).unwrap());
}

/// Skip a vector. Panics if there isn't enough space.
Expand Down Expand Up @@ -545,7 +545,7 @@ mod tests {
}

#[test]
#[should_panic]
#[should_panic(expected = "insufficient data")]
fn skip_too_much() {
let enc = Encoder::from_hex("ff");
let mut dec = enc.as_decoder();
Expand All @@ -561,15 +561,15 @@ mod tests {
}

#[test]
#[should_panic]
#[should_panic(expected = "insufficient data")]
fn skip_vec_too_much() {
let enc = Encoder::from_hex("ff1234");
let mut dec = enc.as_decoder();
dec.skip_vec(1);
}

#[test]
#[should_panic]
#[should_panic(expected = "invalid length")]
fn skip_vec_short_length() {
let enc = Encoder::from_hex("ff");
let mut dec = enc.as_decoder();
Expand All @@ -584,15 +584,15 @@ mod tests {
}

#[test]
#[should_panic]
#[should_panic(expected = "insufficient data")]
fn skip_vvec_too_much() {
let enc = Encoder::from_hex("0f1234");
let mut dec = enc.as_decoder();
dec.skip_vvec();
}

#[test]
#[should_panic]
#[should_panic(expected = "invalid length")]
fn skip_vvec_short_length() {
let enc = Encoder::from_hex("ff");
let mut dec = enc.as_decoder();
Expand All @@ -611,7 +611,7 @@ mod tests {
}

#[test]
#[should_panic]
#[should_panic(expected = "Varint value too large")]
fn encoded_length_oob() {
_ = Encoder::varint_len(1 << 62);
}
Expand All @@ -628,7 +628,7 @@ mod tests {
}

#[test]
#[should_panic]
#[should_panic(expected = "Varint value too large")]
fn encoded_vvec_length_oob() {
_ = Encoder::vvec_len(1 << 62);
}
Expand Down Expand Up @@ -752,7 +752,7 @@ mod tests {
}

#[test]
#[should_panic]
#[should_panic(expected = "assertion failed")]
fn encode_vec_with_overflow() {
let mut enc = Encoder::default();
enc.encode_vec_with(1, |enc_inner| {
Expand Down
4 changes: 2 additions & 2 deletions neqo-crypto/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,8 @@ impl SecretAgent {
/// Install an extension handler.
///
/// This can be called multiple times with different values for `ext`. The handler is provided as
/// Rc<RefCell<>> so that the caller is able to hold a reference to the handler and later access any
/// state that it accumulates.
/// `Rc<RefCell<dyn T>>` so that the caller is able to hold a reference to the handler and later
/// access any state that it accumulates.
///
/// # Errors
/// When the extension handler can't be successfully installed.
Expand Down
4 changes: 2 additions & 2 deletions neqo-crypto/tests/hp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ fn chacha20_ctr() {
}

#[test]
#[should_panic]
#[should_panic(expected = "out of range")]
fn aes_short() {
let hp = make_hp(TLS_AES_128_GCM_SHA256);
mem::drop(hp.mask(&[0; 15]));
}

#[test]
#[should_panic]
#[should_panic(expected = "out of range")]
fn chacha20_short() {
let hp = make_hp(TLS_CHACHA20_POLY1305_SHA256);
mem::drop(hp.mask(&[0; 15]));
Expand Down
53 changes: 32 additions & 21 deletions neqo-transport/src/cc/classic_cc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@
// Congestion control
#![deny(clippy::pedantic)]

use std::cmp::{max, min};
use std::fmt::{self, Debug, Display};
use std::time::{Duration, Instant};
use std::{
cmp::{max, min},
fmt::{self, Debug, Display},
time::{Duration, Instant},
};

use super::CongestionControl;

use crate::cc::MAX_DATAGRAM_SIZE;
use crate::packet::PacketNumber;
use crate::qlog::{self, QlogMetric};
use crate::sender::PACING_BURST_SIZE;
use crate::tracking::SentPacket;
use ::qlog::events::quic::CongestionStateUpdated;
use ::qlog::events::EventData;
use crate::{
cc::MAX_DATAGRAM_SIZE,
packet::PacketNumber,
qlog::{self, QlogMetric},
sender::PACING_BURST_SIZE,
tracking::SentPacket,
};
use ::qlog::events::{quic::CongestionStateUpdated, EventData};
use neqo_common::{const_max, const_min, qdebug, qinfo, qlog::NeqoQlog, qtrace};

pub const CWND_INITIAL_PKTS: usize = 10;
Expand Down Expand Up @@ -439,7 +442,11 @@ impl<T: WindowAdjustment> ClassicCongestionControl<T> {
continue;
}
if let Some(t) = start {
if p.time_sent.checked_duration_since(t).unwrap() > pc_period {
let elapsed = p
.time_sent
.checked_duration_since(t)
.expect("time is monotonic");
if elapsed > pc_period {
qinfo!([self], "persistent congestion");
self.congestion_window = CWND_MIN;
self.acked_bytes = 0;
Expand Down Expand Up @@ -523,15 +530,19 @@ mod tests {
use super::{
ClassicCongestionControl, WindowAdjustment, CWND_INITIAL, CWND_MIN, PERSISTENT_CONG_THRESH,
};
use crate::cc::cubic::{Cubic, CUBIC_BETA_USIZE_DIVIDEND, CUBIC_BETA_USIZE_DIVISOR};
use crate::cc::new_reno::NewReno;
use crate::cc::{
CongestionControl, CongestionControlAlgorithm, CWND_INITIAL_PKTS, MAX_DATAGRAM_SIZE,
use crate::{
cc::{
cubic::{Cubic, CUBIC_BETA_USIZE_DIVIDEND, CUBIC_BETA_USIZE_DIVISOR},
new_reno::NewReno,
CongestionControl, CongestionControlAlgorithm, CWND_INITIAL_PKTS, MAX_DATAGRAM_SIZE,
},
packet::{PacketNumber, PacketType},
tracking::SentPacket,
};
use std::{
convert::TryFrom,
time::{Duration, Instant},
};
use crate::packet::{PacketNumber, PacketType};
use crate::tracking::SentPacket;
use std::convert::TryFrom;
use std::time::{Duration, Instant};
use test_fixture::now;

const PTO: Duration = Duration::from_millis(100);
Expand Down Expand Up @@ -952,7 +963,7 @@ mod tests {

/// The code asserts on ordering errors.
#[test]
#[should_panic]
#[should_panic(expected = "time is monotonic")]
fn persistent_congestion_unsorted_newreno() {
let lost = make_lost(&[PERSISTENT_CONG_THRESH + 2, 1]);
assert!(!persistent_congestion_by_pto(
Expand All @@ -965,7 +976,7 @@ mod tests {

/// The code asserts on ordering errors.
#[test]
#[should_panic]
#[should_panic(expected = "time is monotonic")]
fn persistent_congestion_unsorted_cubic() {
let lost = make_lost(&[PERSISTENT_CONG_THRESH + 2, 1]);
assert!(!persistent_congestion_by_pto(
Expand Down
2 changes: 1 addition & 1 deletion neqo-transport/src/fc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ mod test {
remote_stream_limits(Role::Server, 0, 2);
}

#[should_panic]
#[should_panic(expected = ".is_allowed")]
#[test]
fn remote_stream_limits_asserts_if_limit_exceeded() {
let mut fc = RemoteStreamLimits::new(2, 1, Role::Client);
Expand Down
10 changes: 5 additions & 5 deletions neqo-transport/src/tparams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,19 +918,19 @@ mod tests {
}

#[test]
#[should_panic]
#[should_panic(expected = "v4.is_some() || v6.is_some()")]
fn preferred_address_neither() {
_ = PreferredAddress::new(None, None);
}

#[test]
#[should_panic]
#[should_panic(expected = ".is_unspecified")]
fn preferred_address_v4_unspecified() {
_ = PreferredAddress::new(Some(SocketAddrV4::new(Ipv4Addr::from(0), 443)), None);
}

#[test]
#[should_panic]
#[should_panic(expected = "left != right")]
fn preferred_address_v4_zero_port() {
_ = PreferredAddress::new(
Some(SocketAddrV4::new(Ipv4Addr::from(0xc000_0201), 0)),
Expand All @@ -939,13 +939,13 @@ mod tests {
}

#[test]
#[should_panic]
#[should_panic(expected = ".is_unspecified")]
fn preferred_address_v6_unspecified() {
_ = PreferredAddress::new(None, Some(SocketAddrV6::new(Ipv6Addr::from(0), 443, 0, 0)));
}

#[test]
#[should_panic]
#[should_panic(expected = "left != right")]
fn preferred_address_v6_zero_port() {
_ = PreferredAddress::new(None, Some(SocketAddrV6::new(Ipv6Addr::from(1), 0, 0, 0)));
}
Expand Down

0 comments on commit b0eb12a

Please sign in to comment.