Skip to content

Commit

Permalink
Correctly run clippy on sub-crates (#9398)
Browse files Browse the repository at this point in the history
  • Loading branch information
alex authored Aug 10, 2023
1 parent 1336f17 commit ecf2129
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 3 additions & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ def rust(session: nox.Session) -> None:

with session.chdir("src/rust/"):
session.run("cargo", "fmt", "--all", "--", "--check", external=True)
session.run("cargo", "clippy", "--", "-D", "warnings", external=True)
session.run(
"cargo", "clippy", "--all", "--", "-D", "warnings", external=True
)

build_output = session.run(
"cargo",
Expand Down
9 changes: 5 additions & 4 deletions src/rust/cryptography-x509-validation/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,14 @@ impl<'a> DNSPattern<'a> {
}
}

#[derive(Copy, Clone, Debug, PartialEq)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct IPAddress(IpAddr);

/// An `IPAddress` represents an IP address as defined in [RFC 5280 4.2.1.6].
///
/// [RFC 5280 4.2.1.6]: https://datatracker.ietf.org/doc/html/rfc5280#section-4.2.1.6
impl IPAddress {
#[allow(clippy::should_implement_trait)]
pub fn from_str(s: &str) -> Option<Self> {
IpAddr::from_str(s).ok().map(Self::from)
}
Expand Down Expand Up @@ -175,7 +176,7 @@ impl IPAddress {
pub fn mask(&self, prefix: u8) -> Self {
match self.0 {
IpAddr::V4(a) => {
let prefix = 32u8.checked_sub(prefix).unwrap_or(0).into();
let prefix = 32u8.saturating_sub(prefix).into();
let masked = u32::from_be_bytes(a.octets())
& u32::MAX
.checked_shr(prefix)
Expand All @@ -185,7 +186,7 @@ impl IPAddress {
Self::from_bytes(&masked.to_be_bytes()).unwrap()
}
IpAddr::V6(a) => {
let prefix = 128u8.checked_sub(prefix).unwrap_or(0).into();
let prefix = 128u8.saturating_sub(prefix).into();
let masked = u128::from_be_bytes(a.octets())
& u128::MAX
.checked_shr(prefix)
Expand All @@ -204,7 +205,7 @@ impl From<IpAddr> for IPAddress {
}
}

#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Eq)]
pub struct IPRange {
address: IPAddress,
prefix: u8,
Expand Down

0 comments on commit ecf2129

Please sign in to comment.