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,21 +91,19 @@ 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() { unsafe { OwnedFd::from_raw_fd(fd) }
unsafe { OwnedFd::from_raw_fd(fd) } } else {
} else { return Ok(None);
return Ok(None); };
}; // Close all others
// Close all others for fd in scm_rights {
for fd in scm_rights { unsafe { libc::close(fd) };
unsafe { libc::close(fd) };
}
return Ok(Some(fd));
} }
return Ok(Some(fd));
} }
} }
Ok(None) Ok(None)
@ -119,13 +117,11 @@ 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() {

View File

@ -201,13 +201,10 @@ 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)
} }