From 6ddf7601ca8c82d61c49be1fcec27884ec266dfa Mon Sep 17 00:00:00 2001 From: Lawrence Chou Date: Sat, 7 Oct 2023 13:03:59 +0800 Subject: [PATCH] Fix E0308 to compile on apple hardware `S_IWUSR` is of type `mode_t`: https://github.com/rust-lang/libc/blob/d80e8bd3056d82fec80c022819084bdb0be3bdaa/src/unix/bsd/apple/mod.rs#L2928 On apple, `mode_t` is u16 https://github.com/rust-lang/libc/blob/d80e8bd3056d82fec80c022819084bdb0be3bdaa/src/unix/bsd/apple/mod.rs#L11 On linux, `mode_t` is u32 https://github.com/rust-lang/libc/blob/d80e8bd3056d82fec80c022819084bdb0be3bdaa/src/unix/linux_like/linux/mod.rs#L6 --- src/cap.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/cap.rs b/src/cap.rs index f1a2430b4..792134634 100644 --- a/src/cap.rs +++ b/src/cap.rs @@ -31,8 +31,10 @@ use tokio::runtime::Handle; /// Change the provided `Permissions` by making it read-only. #[cfg(unix)] fn read_only(mut permissions: Permissions) -> Permissions { - // Remove user write permissions. - let () = permissions.set_mode(permissions.mode() & !S_IWUSR); + // Remove user write permissions. Note that `S_IWUSR` is `u16` on some + // platforms. + #[allow(trivial_numeric_casts, clippy::unnecessary_cast)] + let () = permissions.set_mode(permissions.mode() & !S_IWUSR as u32); permissions } @@ -47,7 +49,8 @@ fn read_only(mut permissions: Permissions) -> Permissions { #[cfg(unix)] fn writeable(mut permissions: Permissions) -> Permissions { // Set user write permissions. - let () = permissions.set_mode(permissions.mode() | S_IWUSR); + #[allow(trivial_numeric_casts, clippy::unnecessary_cast)] + let () = permissions.set_mode(permissions.mode() | S_IWUSR as u32); permissions }