Skip to content

Commit 5680df8

Browse files
bors[bot]asomers
andauthored
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 <[email protected]>
2 parents c375a10 + 31162fd commit 5680df8

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
@@ -19,7 +20,7 @@ build: &BUILD
1920
- rustc -Vv
2021
- $TOOL $BUILD $ZFLAGS --target $TARGET --all-targets
2122
- $TOOL doc $ZFLAGS --no-deps --target $TARGET
22-
- $TOOL clippy $ZFLAGS --target $TARGET --all-targets -- -D warnings
23+
- $TOOL clippy $ZFLAGS --target $TARGET --all-targets -- $CLIPPYFLAGS
2324
- if [ -z "$NOHACK" ]; then mkdir -p $HOME/.cargo/bin; export PATH=$HOME/.cargo/bin:$PATH; fi
2425
- 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
2526
- if [ -z "$NOHACK" ]; then $TOOL hack $ZFLAGS check --target $TARGET --each-feature; fi
@@ -253,6 +254,7 @@ task:
253254
env:
254255
HOST: x86_64-unknown-linux-gnu
255256
TARGET: x86_64-unknown-redox
257+
CLIPPYFLAGS: -D warnings
256258
setup_script:
257259
- rustup target add $TARGET
258260
- rustup component add clippy
@@ -267,6 +269,7 @@ task:
267269
BUILD: check
268270
HOST: x86_64-unknown-linux-gnu
269271
ZFLAGS: -Zbuild-std
272+
CLIPPYFLAGS: -D warnings
270273
matrix:
271274
- name: DragonFly BSD x86_64
272275
env:

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ assert-impl = "0.1"
8080
lazy_static = "1.4"
8181
parking_lot = "0.12"
8282
rand = "0.8"
83-
tempfile = "3.3.0"
83+
# tempfile 3.7.0 doesn't build on Haiku
84+
# https://github.com/Stebalien/tempfile/issues/246
85+
tempfile = ">=3.3.0, < 3.7.0"
8486
semver = "1.0.7"
8587

8688
[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
@@ -1619,18 +1619,18 @@ impl<S> MultiHeaders<S> {
16191619

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

16251625
let items = addresses
16261626
.iter_mut()
16271627
.enumerate()
16281628
.map(|(ix, address)| {
1629-
let (ptr, cap) = match &cmsg_buffers {
1630-
Some(v) => ((&v[ix * msg_controllen] as *const u8), msg_controllen),
1631-
None => (std::ptr::null(), 0),
1629+
let (ptr, cap) = match &mut cmsg_buffers {
1630+
Some(v) => ((&mut v[ix * msg_controllen] as *mut u8), msg_controllen),
1631+
None => (std::ptr::null_mut(), 0),
16321632
};
1633-
let msg_hdr = unsafe { pack_mhdr_to_receive(std::ptr::null(), 0, ptr, cap, address.as_mut_ptr()) };
1633+
let msg_hdr = unsafe { pack_mhdr_to_receive(std::ptr::null_mut(), 0, ptr, cap, address.as_mut_ptr()) };
16341634
libc::mmsghdr {
16351635
msg_hdr,
16361636
msg_len: 0,
@@ -1961,9 +1961,9 @@ unsafe fn read_mhdr<'a, 'i, S>(
19611961
///
19621962
/// Buffers must remain valid for the whole lifetime of msghdr
19631963
unsafe fn pack_mhdr_to_receive<S>(
1964-
iov_buffer: *const IoSliceMut,
1964+
iov_buffer: *mut IoSliceMut,
19651965
iov_buffer_len: usize,
1966-
cmsg_buffer: *const u8,
1966+
cmsg_buffer: *mut u8,
19671967
cmsg_capacity: usize,
19681968
address: *mut S,
19691969
) -> msghdr
@@ -1999,7 +1999,7 @@ fn pack_mhdr_to_send<'a, I, C, S>(
19991999

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

20692069
let ret = unsafe { libc::recvmsg(fd, &mut mhdr, flags.bits()) };
@@ -2209,7 +2209,7 @@ pub fn recv(sockfd: RawFd, buf: &mut [u8], flags: MsgFlags) -> Result<usize> {
22092209
unsafe {
22102210
let ret = libc::recv(
22112211
sockfd,
2212-
buf.as_ptr() as *mut c_void,
2212+
buf.as_mut_ptr() as *mut c_void,
22132213
buf.len() as size_t,
22142214
flags.bits(),
22152215
);
@@ -2233,7 +2233,7 @@ pub fn recvfrom<T: SockaddrLike>(
22332233

22342234
let ret = Errno::result(libc::recvfrom(
22352235
sockfd,
2236-
buf.as_ptr() as *mut c_void,
2236+
buf.as_mut_ptr() as *mut c_void,
22372237
buf.len() as size_t,
22382238
0,
22392239
addr.as_mut_ptr() as *mut sockaddr,

src/sys/uio.rs

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

0 commit comments

Comments
 (0)