Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
2086: Clippy cleanup r=asomers a=asomers

Clippy found some const-correctness issues in internal APIs, but nothing user-facing.

Co-authored-by: Alan Somers <asomers@gmail.com>
  • Loading branch information
bors[bot] and asomers committed Aug 27, 2023
1 parent 52ab885 commit 3480351
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 13 deletions.
5 changes: 4 additions & 1 deletion .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ cargo_cache:
env:
# Build by default; don't just check
BUILD: build
CLIPPYFLAGS: -D warnings -A unknown-lints
RUSTFLAGS: -D warnings
RUSTDOCFLAGS: -D warnings
TOOL: cargo
Expand All @@ -20,7 +21,7 @@ build: &BUILD
- rustc +$TOOLCHAIN -Vv
- $TOOL +$TOOLCHAIN $BUILD $ZFLAGS --target $TARGET --all-targets
- $TOOL +$TOOLCHAIN doc $ZFLAGS --no-deps --target $TARGET
- $TOOL +$TOOLCHAIN clippy $ZFLAGS --target $TARGET --all-targets -- -D warnings
- $TOOL +$TOOLCHAIN clippy $ZFLAGS --target $TARGET --all-targets -- $CLIPPYFLAGS
- if [ -z "$NOHACK" ]; then mkdir -p $HOME/.cargo/bin; export PATH=$HOME/.cargo/bin:$PATH; fi
- if [ -z "$NOHACK" ]; then curl -LsSf https://github.com/taiki-e/cargo-hack/releases/latest/download/cargo-hack-${HOST:-$TARGET}.tar.gz | tar xzf - -C ~/.cargo/bin; fi
- if [ -z "$NOHACK" ]; then $TOOL +$TOOLCHAIN hack $ZFLAGS check --target $TARGET --each-feature; fi
Expand Down Expand Up @@ -259,6 +260,7 @@ task:
TARGET: x86_64-unknown-redox
# Redox's MSRV policy is unclear. Until they define it, use nightly.
TOOLCHAIN: nightly
CLIPPYFLAGS: -D warnings
setup_script:
- rustup target add $TARGET
- rustup toolchain install $TOOLCHAIN --profile minimal --target $TARGET
Expand All @@ -275,6 +277,7 @@ task:
HOST: x86_64-unknown-linux-gnu
TOOLCHAIN: nightly
ZFLAGS: -Zbuild-std
CLIPPYFLAGS: -D warnings
matrix:
- name: DragonFly BSD x86_64
env:
Expand Down
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ assert-impl = "0.1"
lazy_static = "1.4"
parking_lot = "0.12"
rand = "0.8"
tempfile = "3.3.0"
# tempfile 3.7.0 doesn't build on Haiku
# https://github.com/Stebalien/tempfile/issues/246
tempfile = ">=3.3.0, < 3.7.0"
semver = "1.0.7"

[target.'cfg(any(target_os = "android", target_os = "linux"))'.dev-dependencies]
Expand Down
3 changes: 3 additions & 0 deletions src/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ impl Drop for Dir {
}
}

// The pass by mut is technically needless only because the inner NonNull is
// Copy. But philosophically we're mutating the Dir, so we pass by mut.
#[allow(clippy::needless_pass_by_ref_mut)]
fn next(dir: &mut Dir) -> Option<Result<Entry>> {
unsafe {
// Note: POSIX specifies that portable applications should dynamically allocate a
Expand Down
22 changes: 11 additions & 11 deletions src/sys/socket/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1617,18 +1617,18 @@ impl<S> MultiHeaders<S> {

// we'll need a cmsg_buffer for each slice, we preallocate a vector and split
// it into "slices" parts
let cmsg_buffers =
let mut cmsg_buffers =
cmsg_buffer.map(|v| vec![0u8; v.capacity() * num_slices].into_boxed_slice());

let items = addresses
.iter_mut()
.enumerate()
.map(|(ix, address)| {
let (ptr, cap) = match &cmsg_buffers {
Some(v) => ((&v[ix * msg_controllen] as *const u8), msg_controllen),
None => (std::ptr::null(), 0),
let (ptr, cap) = match &mut cmsg_buffers {
Some(v) => ((&mut v[ix * msg_controllen] as *mut u8), msg_controllen),
None => (std::ptr::null_mut(), 0),
};
let msg_hdr = unsafe { pack_mhdr_to_receive(std::ptr::null(), 0, ptr, cap, address.as_mut_ptr()) };
let msg_hdr = unsafe { pack_mhdr_to_receive(std::ptr::null_mut(), 0, ptr, cap, address.as_mut_ptr()) };
libc::mmsghdr {
msg_hdr,
msg_len: 0,
Expand Down Expand Up @@ -1959,9 +1959,9 @@ unsafe fn read_mhdr<'a, 'i, S>(
///
/// Buffers must remain valid for the whole lifetime of msghdr
unsafe fn pack_mhdr_to_receive<S>(
iov_buffer: *const IoSliceMut,
iov_buffer: *mut IoSliceMut,
iov_buffer_len: usize,
cmsg_buffer: *const u8,
cmsg_buffer: *mut u8,
cmsg_capacity: usize,
address: *mut S,
) -> msghdr
Expand Down Expand Up @@ -1997,7 +1997,7 @@ fn pack_mhdr_to_send<'a, I, C, S>(

// The message header must be initialized before the individual cmsgs.
let cmsg_ptr = if capacity > 0 {
cmsg_buffer.as_ptr() as *mut c_void
cmsg_buffer.as_mut_ptr() as *mut c_void
} else {
ptr::null_mut()
};
Expand Down Expand Up @@ -2061,7 +2061,7 @@ pub fn recvmsg<'a, 'outer, 'inner, S>(fd: RawFd, iov: &'outer mut [IoSliceMut<'i
.map(|v| (v.as_mut_ptr(), v.capacity()))
.unwrap_or((ptr::null_mut(), 0));
let mut mhdr = unsafe {
pack_mhdr_to_receive(iov.as_ref().as_ptr(), iov.len(), msg_control, msg_controllen, address.as_mut_ptr())
pack_mhdr_to_receive(iov.as_mut().as_mut_ptr(), iov.len(), msg_control, msg_controllen, address.as_mut_ptr())
};

let ret = unsafe { libc::recvmsg(fd, &mut mhdr, flags.bits()) };
Expand Down Expand Up @@ -2207,7 +2207,7 @@ pub fn recv(sockfd: RawFd, buf: &mut [u8], flags: MsgFlags) -> Result<usize> {
unsafe {
let ret = libc::recv(
sockfd,
buf.as_ptr() as *mut c_void,
buf.as_mut_ptr() as *mut c_void,
buf.len() as size_t,
flags.bits(),
);
Expand All @@ -2231,7 +2231,7 @@ pub fn recvfrom<T: SockaddrLike>(

let ret = Errno::result(libc::recvfrom(
sockfd,
buf.as_ptr() as *mut c_void,
buf.as_mut_ptr() as *mut c_void,
buf.len() as size_t,
0,
addr.as_mut_ptr() as *mut libc::sockaddr,
Expand Down
6 changes: 6 additions & 0 deletions src/sys/uio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ pub fn writev(fd: RawFd, iov: &[IoSlice<'_>]) -> Result<usize> {
/// Low-level vectored read from a raw file descriptor
///
/// See also [readv(2)](https://pubs.opengroup.org/onlinepubs/9699919799/functions/readv.html)
// Clippy doesn't know that we need to pass iov mutably only because the
// mutation happens after converting iov to a pointer
#[allow(clippy::needless_pass_by_ref_mut)]
pub fn readv(fd: RawFd, iov: &mut [IoSliceMut<'_>]) -> Result<usize> {
// SAFETY: same as in writev(), IoSliceMut is ABI-compatible with iovec
let res = unsafe {
Expand Down Expand Up @@ -71,6 +74,9 @@ pub fn pwritev(fd: RawFd, iov: &[IoSlice<'_>], offset: off_t) -> Result<usize> {
/// See also: [`readv`](fn.readv.html) and [`pread`](fn.pread.html)
#[cfg(not(any(target_os = "redox", target_os = "haiku")))]
#[cfg_attr(docsrs, doc(cfg(all())))]
// Clippy doesn't know that we need to pass iov mutably only because the
// mutation happens after converting iov to a pointer
#[allow(clippy::needless_pass_by_ref_mut)]
pub fn preadv(
fd: RawFd,
iov: &mut [IoSliceMut<'_>],
Expand Down

0 comments on commit 3480351

Please sign in to comment.