From 6e7bddd1540565a9da7f7e56ddf5851d1786a3dd Mon Sep 17 00:00:00 2001 From: Ryan Zoeller Date: Sat, 8 Oct 2022 13:48:59 -0500 Subject: Fix clippy warnings on nightly Clippy is now smarter about detecting unnecessary casts and useless conversions, which means we need to be more explicit about when the conversions are needed for a subset of platforms. Required changes found by repeatedly running the following command against a list of the supported platforms. `xargs -t -I {} sh -c "cargo clippy -Zbuild-std --target {} --all-targets -- -D warnings || exit 255"` I removed the casts it complained about, and then restored them with an `#[allow]` if a later target needed the cast. --- src/sys/socket/addr.rs | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'src/sys/socket/addr.rs') diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs index 6b2ba21c..07d68e1f 100644 --- a/src/sys/socket/addr.rs +++ b/src/sys/socket/addr.rs @@ -935,7 +935,7 @@ impl SockaddrLike for UnixAddr { return None; } } - if (*addr).sa_family as i32 != libc::AF_UNIX as i32 { + if (*addr).sa_family as i32 != libc::AF_UNIX { return None; } let mut su: libc::sockaddr_un = mem::zeroed(); @@ -1192,7 +1192,7 @@ impl SockaddrLike for SockaddrIn { return None; } } - if (*addr).sa_family as i32 != libc::AF_INET as i32 { + if (*addr).sa_family as i32 != libc::AF_INET { return None; } Some(Self(ptr::read_unaligned(addr as *const _))) @@ -1298,7 +1298,7 @@ impl SockaddrLike for SockaddrIn6 { return None; } } - if (*addr).sa_family as i32 != libc::AF_INET6 as i32 { + if (*addr).sa_family as i32 != libc::AF_INET6 { return None; } Some(Self(ptr::read_unaligned(addr as *const _))) @@ -2101,7 +2101,7 @@ pub mod netlink { return None; } } - if (*addr).sa_family as i32 != libc::AF_NETLINK as i32 { + if (*addr).sa_family as i32 != libc::AF_NETLINK { return None; } Some(Self(ptr::read_unaligned(addr as *const _))) @@ -2145,7 +2145,7 @@ pub mod alg { return None; } } - if (*addr).sa_family as i32 != libc::AF_ALG as i32 { + if (*addr).sa_family as i32 != libc::AF_ALG { return None; } Some(Self(ptr::read_unaligned(addr as *const _))) @@ -2259,7 +2259,7 @@ pub mod sys_control { return None; } } - if (*addr).sa_family as i32 != libc::AF_SYSTEM as i32 { + if (*addr).sa_family as i32 != libc::AF_SYSTEM { return None; } Some(Self(ptr::read_unaligned(addr as *const _))) @@ -2366,12 +2366,12 @@ mod datalink { // Returns an Option just for cross-platform compatibility pub fn addr(&self) -> Option<[u8; 6]> { Some([ - self.0.sll_addr[0] as u8, - self.0.sll_addr[1] as u8, - self.0.sll_addr[2] as u8, - self.0.sll_addr[3] as u8, - self.0.sll_addr[4] as u8, - self.0.sll_addr[5] as u8, + self.0.sll_addr[0], + self.0.sll_addr[1], + self.0.sll_addr[2], + self.0.sll_addr[3], + self.0.sll_addr[4], + self.0.sll_addr[5], ]) } } @@ -2402,7 +2402,7 @@ mod datalink { return None; } } - if (*addr).sa_family as i32 != libc::AF_PACKET as i32 { + if (*addr).sa_family as i32 != libc::AF_PACKET { return None; } Some(Self(ptr::read_unaligned(addr as *const _))) @@ -2477,6 +2477,8 @@ mod datalink { } /// Physical-layer address (MAC) + // The cast is not unnecessary on all platforms. + #[allow(clippy::unnecessary_cast)] pub fn addr(&self) -> Option<[u8; 6]> { let nlen = self.nlen(); let data = self.0.sdl_data; @@ -2522,7 +2524,7 @@ mod datalink { return None; } } - if (*addr).sa_family as i32 != libc::AF_LINK as i32 { + if (*addr).sa_family as i32 != libc::AF_LINK { return None; } Some(Self(ptr::read_unaligned(addr as *const _))) @@ -2566,7 +2568,7 @@ pub mod vsock { return None; } } - if (*addr).sa_family as i32 != libc::AF_VSOCK as i32 { + if (*addr).sa_family as i32 != libc::AF_VSOCK { return None; } Some(Self(ptr::read_unaligned(addr as *const _))) -- cgit v1.2.3