Address clippy warnings

This commit is contained in:
topjohnwu 2025-01-30 02:19:30 +08:00 committed by John Wu
parent 7f7f625864
commit c05e963f37
3 changed files with 22 additions and 29 deletions

View File

@ -70,5 +70,5 @@ pub mod ffi {
#[inline(always)] #[inline(always)]
pub(crate) fn check_env(env: &str) -> bool { pub(crate) fn check_env(env: &str) -> bool {
env::var(env).map_or(false, |var| var == "true") env::var(env).is_ok_and(|var| var == "true")
} }

View File

@ -32,7 +32,7 @@ impl<T: Read> IpcRead for T {
let mut val: E = Zeroable::zeroed(); let mut val: E = Zeroable::zeroed();
for _ in 0..len { for _ in 0..len {
self.read_pod(&mut val)?; self.read_pod(&mut val)?;
vec.push(val.clone()); vec.push(val);
} }
Ok(vec) Ok(vec)
} }
@ -91,8 +91,7 @@ impl UnixSocketExt for UnixStream {
let mut ancillary = SocketAncillary::new(&mut buf); let mut ancillary = SocketAncillary::new(&mut buf);
let iov = IoSliceMut::new(bytes_of_mut(&mut fd_count)); let iov = IoSliceMut::new(bytes_of_mut(&mut fd_count));
self.recv_vectored_with_ancillary(&mut [iov], &mut ancillary)?; self.recv_vectored_with_ancillary(&mut [iov], &mut ancillary)?;
for msg in ancillary.messages() { for msg in ancillary.messages().flatten() {
if let Ok(msg) = msg {
if let AncillaryData::ScmRights(mut scm_rights) = msg { if let AncillaryData::ScmRights(mut scm_rights) = msg {
// We only want the first one // We only want the first one
let fd = if let Some(fd) = scm_rights.next() { let fd = if let Some(fd) = scm_rights.next() {
@ -107,7 +106,6 @@ impl UnixSocketExt for UnixStream {
return Ok(Some(fd)); return Ok(Some(fd));
} }
} }
}
Ok(None) Ok(None)
} }
@ -119,15 +117,13 @@ impl UnixSocketExt for UnixStream {
let iov = IoSliceMut::new(bytes_of_mut(&mut fd_count)); let iov = IoSliceMut::new(bytes_of_mut(&mut fd_count));
self.recv_vectored_with_ancillary(&mut [iov], &mut ancillary)?; self.recv_vectored_with_ancillary(&mut [iov], &mut ancillary)?;
let mut fds: Vec<OwnedFd> = Vec::new(); let mut fds: Vec<OwnedFd> = Vec::new();
for msg in ancillary.messages() { for msg in ancillary.messages().flatten() {
if let Ok(msg) = msg {
if let AncillaryData::ScmRights(scm_rights) = msg { if let AncillaryData::ScmRights(scm_rights) = msg {
fds = scm_rights fds = scm_rights
.map(|fd| unsafe { OwnedFd::from_raw_fd(fd) }) .map(|fd| unsafe { OwnedFd::from_raw_fd(fd) })
.collect(); .collect();
} }
} }
}
if fd_count as usize != fds.len() { if fd_count as usize != fds.len() {
warn!( warn!(
"Received unexpected number of fds: expected={} actual={}", "Received unexpected number of fds: expected={} actual={}",

View File

@ -201,14 +201,11 @@ fn parse_xperms<'a>(tokens: &mut Tokens<'a>) -> ParseResult<'a, Vec<Xperm>> {
} }
fn match_string<'a>(tokens: &mut Tokens<'a>, pattern: &str) -> ParseResult<'a, ()> { fn match_string<'a>(tokens: &mut Tokens<'a>, pattern: &str) -> ParseResult<'a, ()> {
match tokens.next() { if let Some(Token::ID(s)) = tokens.next() {
Some(Token::ID(s)) => {
if s == pattern { if s == pattern {
return Ok(()); return Ok(());
} }
} }
_ => {}
}
Err(ParseError::General) Err(ParseError::General)
} }