Skip to content

Commit

Permalink
Merge pull request #187 from mozilla/pedantic-regressions
Browse files Browse the repository at this point in the history
Fix some clippy::pedantic regressions
  • Loading branch information
mergify[bot] committed Sep 5, 2019
2 parents f20e933 + b4d1369 commit 405da2e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
15 changes: 7 additions & 8 deletions neqo-common/src/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,13 @@ impl<'a> Decoder<'a> {
Some(l) => l,
_ => return None,
};
match usize::try_from(len) {
Ok(l) => self.decode(l),
_ => {
// sizeof(usize) < sizeof(u64) and the value is greater than
// usize can hold. Throw away the rest of the input.
self.offset = self.buf.len();
None
}
if let Ok(l) = usize::try_from(len) {
self.decode(l)
} else {
// sizeof(usize) < sizeof(u64) and the value is greater than
// usize can hold. Throw away the rest of the input.
self.offset = self.buf.len();
None
}
}

Expand Down
1 change: 0 additions & 1 deletion neqo-crypto/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ impl From<PRErrorCode> for AuthenticationStatus {
mozpkix::MOZILLA_PKIX_ERROR_ADDITIONAL_POLICY_CONSTRAINT_FAILED => {
Self::PolicyRejection
}
sec::SEC_ERROR_LIBRARY_FAILURE => Self::Unknown,
_ => Self::Unknown,
}
}
Expand Down
25 changes: 13 additions & 12 deletions neqo-transport/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ pub enum State {

// Implement Ord so that we can enforce monotonic state progression.
impl PartialOrd for State {
#[allow(clippy::match_same_arms)] // Lint bug: rust-lang/rust-clippy#860
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
if std::mem::discriminant(self) == std::mem::discriminant(other) {
return Some(Ordering::Equal);
Expand Down Expand Up @@ -141,8 +142,8 @@ struct Path {

impl Path {
// Used to create a path when receiving a packet.
pub fn new(d: &Datagram, remote_cid: ConnectionId) -> Path {
Path {
pub fn new(d: &Datagram, remote_cid: ConnectionId) -> Self {
Self {
local: d.destination(),
remote: d.source(),
local_cids: Vec::new(),
Expand Down Expand Up @@ -296,9 +297,9 @@ impl Connection {
protocols: &[impl AsRef<str>],
local_addr: SocketAddr,
remote_addr: SocketAddr,
) -> Res<Connection> {
) -> Res<Self> {
let dcid = ConnectionId::generate(CID_LENGTH);
let mut c = Connection::new(
let mut c = Self::new(
Role::Client,
Client::new(server_name)?.into(),
None,
Expand All @@ -319,8 +320,8 @@ impl Connection {
certs: &[impl AsRef<str>],
protocols: &[impl AsRef<str>],
anti_replay: &AntiReplay,
) -> Res<Connection> {
Ok(Connection::new(
) -> Res<Self> {
Ok(Self::new(
Role::Server,
Server::new(certs)?.into(),
Some(anti_replay),
Expand Down Expand Up @@ -355,13 +356,13 @@ impl Connection {
anti_replay: Option<&AntiReplay>,
protocols: &[impl AsRef<str>],
paths: Option<Path>,
) -> Connection {
) -> Self {
let tphandler = Rc::new(RefCell::new(TransportParametersHandler::default()));
Connection::set_tp_defaults(&mut tphandler.borrow_mut().local);
Self::set_tp_defaults(&mut tphandler.borrow_mut().local);
let crypto = Crypto::new(agent, protocols, tphandler.clone(), anti_replay)
.expect("TLS should be configured successfully");

Connection {
Self {
version: QUIC_VERSION,
role: r,
state: match r {
Expand Down Expand Up @@ -835,12 +836,12 @@ impl Connection {
}

fn process_migrations(&self, d: &Datagram) -> Res<()> {
if !self.paths.iter().any(|p| p.received_on(&d)) {
if self.paths.iter().any(|p| p.received_on(&d)) {
Ok(())
} else {
// Right now, we don't support any form of migration.
// So generate an error if a packet is received on a new path.
Err(Error::InvalidMigration)
} else {
Ok(())
}
}

Expand Down

0 comments on commit 405da2e

Please sign in to comment.