Skip to content

Commit 6d85712

Browse files
bors[bot]asomers
andcommitted
Merge #2086
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>
1 parent 56d027f commit 6d85712

File tree

5 files changed

+27
-13
lines changed

5 files changed

+27
-13
lines changed

.cirrus.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ cargo_cache:
55
env:
66
# Build by default; don't just check
77
BUILD: build
8+
CLIPPYFLAGS: -D warnings -A unknown-lints
89
RUSTFLAGS: -D warnings
910
RUSTDOCFLAGS: -D warnings
1011
TOOL: cargo
@@ -20,7 +21,7 @@ build: &BUILD
2021
- rustc +$TOOLCHAIN -Vv
2122
- $TOOL +$TOOLCHAIN $BUILD $ZFLAGS --target $TARGET --all-targets
2223
- $TOOL +$TOOLCHAIN doc $ZFLAGS --no-deps --target $TARGET
23-
- $TOOL +$TOOLCHAIN clippy $ZFLAGS --target $TARGET --all-targets -- -D warnings
24+
- $TOOL +$TOOLCHAIN clippy $ZFLAGS --target $TARGET --all-targets -- $CLIPPYFLAGS
2425
- if [ -z "$NOHACK" ]; then mkdir -p $HOME/.cargo/bin; export PATH=$HOME/.cargo/bin:$PATH; fi
2526
- 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
2627
- if [ -z "$NOHACK" ]; then $TOOL +$TOOLCHAIN hack $ZFLAGS check --target $TARGET --each-feature; fi
@@ -259,6 +260,7 @@ task:
259260
TARGET: x86_64-unknown-redox
260261
# Redox's MSRV policy is unclear. Until they define it, use nightly.
261262
TOOLCHAIN: nightly
263+
CLIPPYFLAGS: -D warnings
262264
setup_script:
263265
- rustup target add $TARGET
264266
- rustup toolchain install $TOOLCHAIN --profile minimal --target $TARGET
@@ -275,6 +277,7 @@ task:
275277
HOST: x86_64-unknown-linux-gnu
276278
TOOLCHAIN: nightly
277279
ZFLAGS: -Zbuild-std
280+
CLIPPYFLAGS: -D warnings
278281
matrix:
279282
- name: DragonFly BSD x86_64
280283
env:

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ assert-impl = "0.1"
8282
lazy_static = "1.4"
8383
parking_lot = "0.12"
8484
rand = "0.8"
85-
tempfile = "3.3.0"
85+
# tempfile 3.7.0 doesn't build on Haiku
86+
# https://github.com/Stebalien/tempfile/issues/246
87+
tempfile = ">=3.3.0, < 3.7.0"
8688
semver = "1.0.7"
8789

8890
[target.'cfg(any(target_os = "android", target_os = "linux"))'.dev-dependencies]

src/dir.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ impl Drop for Dir {
101101
}
102102
}
103103

104+
// The pass by mut is technically needless only because the inner NonNull is
105+
// Copy. But philosophically we're mutating the Dir, so we pass by mut.
106+
#[allow(clippy::needless_pass_by_ref_mut)]
104107
fn next(dir: &mut Dir) -> Option<Result<Entry>> {
105108
unsafe {
106109
// Note: POSIX specifies that portable applications should dynamically allocate a

src/sys/socket/mod.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,18 +1617,18 @@ impl<S> MultiHeaders<S> {
16171617

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

16231623
let items = addresses
16241624
.iter_mut()
16251625
.enumerate()
16261626
.map(|(ix, address)| {
1627-
let (ptr, cap) = match &cmsg_buffers {
1628-
Some(v) => ((&v[ix * msg_controllen] as *const u8), msg_controllen),
1629-
None => (std::ptr::null(), 0),
1627+
let (ptr, cap) = match &mut cmsg_buffers {
1628+
Some(v) => ((&mut v[ix * msg_controllen] as *mut u8), msg_controllen),
1629+
None => (std::ptr::null_mut(), 0),
16301630
};
1631-
let msg_hdr = unsafe { pack_mhdr_to_receive(std::ptr::null(), 0, ptr, cap, address.as_mut_ptr()) };
1631+
let msg_hdr = unsafe { pack_mhdr_to_receive(std::ptr::null_mut(), 0, ptr, cap, address.as_mut_ptr()) };
16321632
libc::mmsghdr {
16331633
msg_hdr,
16341634
msg_len: 0,
@@ -1959,9 +1959,9 @@ unsafe fn read_mhdr<'a, 'i, S>(
19591959
///
19601960
/// Buffers must remain valid for the whole lifetime of msghdr
19611961
unsafe fn pack_mhdr_to_receive<S>(
1962-
iov_buffer: *const IoSliceMut,
1962+
iov_buffer: *mut IoSliceMut,
19631963
iov_buffer_len: usize,
1964-
cmsg_buffer: *const u8,
1964+
cmsg_buffer: *mut u8,
19651965
cmsg_capacity: usize,
19661966
address: *mut S,
19671967
) -> msghdr
@@ -1997,7 +1997,7 @@ fn pack_mhdr_to_send<'a, I, C, S>(
19971997

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

20672067
let ret = unsafe { libc::recvmsg(fd, &mut mhdr, flags.bits()) };
@@ -2207,7 +2207,7 @@ pub fn recv(sockfd: RawFd, buf: &mut [u8], flags: MsgFlags) -> Result<usize> {
22072207
unsafe {
22082208
let ret = libc::recv(
22092209
sockfd,
2210-
buf.as_ptr() as *mut c_void,
2210+
buf.as_mut_ptr() as *mut c_void,
22112211
buf.len() as size_t,
22122212
flags.bits(),
22132213
);
@@ -2231,7 +2231,7 @@ pub fn recvfrom<T: SockaddrLike>(
22312231

22322232
let ret = Errno::result(libc::recvfrom(
22332233
sockfd,
2234-
buf.as_ptr() as *mut c_void,
2234+
buf.as_mut_ptr() as *mut c_void,
22352235
buf.len() as size_t,
22362236
0,
22372237
addr.as_mut_ptr() as *mut libc::sockaddr,

src/sys/uio.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ pub fn writev(fd: RawFd, iov: &[IoSlice<'_>]) -> Result<usize> {
2828
/// Low-level vectored read from a raw file descriptor
2929
///
3030
/// See also [readv(2)](https://pubs.opengroup.org/onlinepubs/9699919799/functions/readv.html)
31+
// Clippy doesn't know that we need to pass iov mutably only because the
32+
// mutation happens after converting iov to a pointer
33+
#[allow(clippy::needless_pass_by_ref_mut)]
3134
pub fn readv(fd: RawFd, iov: &mut [IoSliceMut<'_>]) -> Result<usize> {
3235
// SAFETY: same as in writev(), IoSliceMut is ABI-compatible with iovec
3336
let res = unsafe {
@@ -71,6 +74,9 @@ pub fn pwritev(fd: RawFd, iov: &[IoSlice<'_>], offset: off_t) -> Result<usize> {
7174
/// See also: [`readv`](fn.readv.html) and [`pread`](fn.pread.html)
7275
#[cfg(not(any(target_os = "redox", target_os = "haiku")))]
7376
#[cfg_attr(docsrs, doc(cfg(all())))]
77+
// Clippy doesn't know that we need to pass iov mutably only because the
78+
// mutation happens after converting iov to a pointer
79+
#[allow(clippy::needless_pass_by_ref_mut)]
7480
pub fn preadv(
7581
fd: RawFd,
7682
iov: &mut [IoSliceMut<'_>],

0 commit comments

Comments
 (0)