Skip to content

Commit

Permalink
Fix miscellaneous clippy lints. (#893)
Browse files Browse the repository at this point in the history
* Fix miscellaneous clippy lints.

* Fix unused import warnings.
  • Loading branch information
sunfishcode committed Oct 24, 2023
1 parent e2314b7 commit 3f338d8
Show file tree
Hide file tree
Showing 18 changed files with 69 additions and 96 deletions.
52 changes: 26 additions & 26 deletions src/backend/libc/mount/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ bitflags! {
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct FsOpenFlags: c::c_uint {
/// `FSOPEN_CLOEXEC`
const FSOPEN_CLOEXEC = 0x00000001;
const FSOPEN_CLOEXEC = 0x0000_0001;

/// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags>
const _ = !0;
Expand All @@ -109,7 +109,7 @@ bitflags! {
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct FsMountFlags: c::c_uint {
/// `FSMOUNT_CLOEXEC`
const FSMOUNT_CLOEXEC = 0x00000001;
const FSMOUNT_CLOEXEC = 0x0000_0001;

/// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags>
const _ = !0;
Expand Down Expand Up @@ -157,37 +157,37 @@ bitflags! {
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct MountAttrFlags: c::c_uint {
/// `MOUNT_ATTR_RDONLY`
const MOUNT_ATTR_RDONLY = 0x00000001;
const MOUNT_ATTR_RDONLY = 0x0000_0001;

/// `MOUNT_ATTR_NOSUID`
const MOUNT_ATTR_NOSUID = 0x00000002;
const MOUNT_ATTR_NOSUID = 0x0000_0002;

/// `MOUNT_ATTR_NODEV`
const MOUNT_ATTR_NODEV = 0x00000004;
const MOUNT_ATTR_NODEV = 0x0000_0004;

/// `MOUNT_ATTR_NOEXEC`
const MOUNT_ATTR_NOEXEC = 0x00000008;
const MOUNT_ATTR_NOEXEC = 0x0000_0008;

/// `MOUNT_ATTR__ATIME`
const MOUNT_ATTR__ATIME = 0x00000070;
const MOUNT_ATTR__ATIME = 0x0000_0070;

/// `MOUNT_ATTR_RELATIME`
const MOUNT_ATTR_RELATIME = 0x00000000;
const MOUNT_ATTR_RELATIME = 0x0000_0000;

/// `MOUNT_ATTR_NOATIME`
const MOUNT_ATTR_NOATIME = 0x00000010;
const MOUNT_ATTR_NOATIME = 0x0000_0010;

/// `MOUNT_ATTR_STRICTATIME`
const MOUNT_ATTR_STRICTATIME = 0x00000020;
const MOUNT_ATTR_STRICTATIME = 0x0000_0020;

/// `MOUNT_ATTR_NODIRATIME`
const MOUNT_ATTR_NODIRATIME = 0x00000080;
const MOUNT_ATTR_NODIRATIME = 0x0000_0080;

/// `MOUNT_ATTR_NOUSER`
const MOUNT_ATTR_IDMAP = 0x00100000;
const MOUNT_ATTR_IDMAP = 0x0010_0000;

/// `MOUNT_ATTR__ATIME_FLAGS`
const MOUNT_ATTR_NOSYMFOLLOW = 0x00200000;
const MOUNT_ATTR_NOSYMFOLLOW = 0x0020_0000;

/// `MOUNT_ATTR__ATIME_FLAGS`
const MOUNT_ATTR_SIZE_VER0 = 32;
Expand All @@ -207,32 +207,32 @@ bitflags! {
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct MoveMountFlags: c::c_uint {
/// `MOVE_MOUNT_F_EMPTY_PATH`
const MOVE_MOUNT_F_SYMLINKS = 0x00000001;
const MOVE_MOUNT_F_SYMLINKS = 0x0000_0001;

/// `MOVE_MOUNT_F_AUTOMOUNTS`
const MOVE_MOUNT_F_AUTOMOUNTS = 0x00000002;
const MOVE_MOUNT_F_AUTOMOUNTS = 0x0000_0002;

/// `MOVE_MOUNT_F_EMPTY_PATH`
const MOVE_MOUNT_F_EMPTY_PATH = 0x00000004;
const MOVE_MOUNT_F_EMPTY_PATH = 0x0000_0004;

/// `MOVE_MOUNT_T_SYMLINKS`
const MOVE_MOUNT_T_SYMLINKS = 0x00000010;
const MOVE_MOUNT_T_SYMLINKS = 0x0000_0010;

/// `MOVE_MOUNT_T_AUTOMOUNTS`
const MOVE_MOUNT_T_AUTOMOUNTS = 0x00000020;
const MOVE_MOUNT_T_AUTOMOUNTS = 0x0000_0020;

/// `MOVE_MOUNT_T_EMPTY_PATH`
const MOVE_MOUNT_T_EMPTY_PATH = 0x00000040;
const MOVE_MOUNT_T_EMPTY_PATH = 0x0000_0040;

/// `MOVE_MOUNT__MASK`
const MOVE_MOUNT_SET_GROUP = 0x00000100;
const MOVE_MOUNT_SET_GROUP = 0x0000_0100;

// TODO: add when linux 6.5 is released
// /// `MOVE_MOUNT_BENEATH`
// const MOVE_MOUNT_BENEATH = 0x00000200;
// const MOVE_MOUNT_BENEATH = 0x0000_0200;

/// `MOVE_MOUNT__MASK`
const MOVE_MOUNT__MASK = 0x00000377;
const MOVE_MOUNT__MASK = 0x0000_0377;

/// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags>
const _ = !0;
Expand Down Expand Up @@ -281,16 +281,16 @@ bitflags! {
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct FsPickFlags: c::c_uint {
/// `FSPICK_CLOEXEC`
const FSPICK_CLOEXEC = 0x00000001;
const FSPICK_CLOEXEC = 0x0000_0001;

/// `FSPICK_SYMLINK_NOFOLLOW`
const FSPICK_SYMLINK_NOFOLLOW = 0x00000002;
const FSPICK_SYMLINK_NOFOLLOW = 0x0000_0002;

/// `FSPICK_NO_AUTOMOUNT`
const FSPICK_NO_AUTOMOUNT = 0x00000004;
const FSPICK_NO_AUTOMOUNT = 0x0000_0004;

/// `FSPICK_EMPTY_PATH`
const FSPICK_EMPTY_PATH = 0x00000008;
const FSPICK_EMPTY_PATH = 0x0000_0008;

/// <https://docs.rs/bitflags/latest/bitflags/#externally-defined-flags>
const _ = !0;
Expand Down
4 changes: 2 additions & 2 deletions src/backend/libc/termios/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ pub(crate) fn tcsetattr(
// linux-raw-sys' ioctl-generation script for sparc isn't working yet,
// so as a temporary workaround, declare these manually.
#[cfg(any(target_arch = "sparc", target_arch = "sparc64"))]
const TCSETS: u32 = 0x80245409;
const TCSETS: u32 = 0x8024_5409;
#[cfg(any(target_arch = "sparc", target_arch = "sparc64"))]
const TCSETS2: u32 = 0x802c540d;
const TCSETS2: u32 = 0x802c_540d;

// Translate from `optional_actions` into an ioctl request code. On
// MIPS, `optional_actions` already has `TCGETS` added to it.
Expand Down
2 changes: 1 addition & 1 deletion src/backend/linux_raw/param/auxv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ static ENTRY: AtomicUsize = AtomicUsize::new(0);
#[cfg(feature = "alloc")]
fn pr_get_auxv() -> crate::io::Result<Vec<u8>> {
use super::super::conv::{c_int, pass_usize, ret_usize};
const PR_GET_AUXV: c::c_int = 0x41555856;
const PR_GET_AUXV: c::c_int = 0x4155_5856;
let mut buffer = alloc::vec![0u8; 512];
let len = unsafe {
ret_usize(syscall_always_asm!(
Expand Down
6 changes: 2 additions & 4 deletions src/fs/at.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ use crate::fs::Access;
use crate::fs::AtFlags;
#[cfg(apple)]
use crate::fs::CloneFlags;
#[cfg(not(any(apple, target_os = "espidf", target_os = "vita", target_os = "wasi")))]
use crate::fs::FileType;
#[cfg(linux_kernel)]
use crate::fs::RenameFlags;
#[cfg(not(any(target_os = "aix", target_os = "espidf")))]
use crate::fs::Stat;
#[cfg(not(any(apple, target_os = "espidf", target_os = "vita", target_os = "wasi")))]
use crate::fs::{Dev, FileType};
#[cfg(not(any(target_os = "espidf", target_os = "wasi")))]
use crate::fs::{Gid, Uid};
use crate::fs::{Mode, OFlags};
Expand All @@ -33,8 +33,6 @@ use {
#[cfg(not(any(target_os = "espidf", target_os = "vita")))]
use {crate::fs::Timestamps, crate::timespec::Nsecs};

pub use backend::fs::types::{Dev, RawMode};

/// `UTIME_NOW` for use with [`utimensat`].
///
/// [`utimensat`]: crate::fs::utimensat
Expand Down
14 changes: 1 addition & 13 deletions src/fs/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,5 @@
use crate::backend;

pub use crate::io::FdFlags;
#[cfg(not(any(target_os = "espidf", target_os = "vita")))]
pub use backend::fs::types::Access;
pub use backend::fs::types::{Dev, Mode, OFlags};

#[cfg(not(any(target_os = "espidf", target_os = "redox")))]
pub use backend::fs::types::AtFlags;

#[cfg(apple)]
pub use backend::fs::types::{CloneFlags, CopyfileFlags};

#[cfg(linux_kernel)]
pub use backend::fs::types::*;

pub use crate::timespec::{Nsecs, Secs, Timespec};
pub use backend::fs::types::*;
3 changes: 1 addition & 2 deletions src/fs/fadvise.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::{backend, io};
use backend::fd::AsFd;

pub use backend::fs::types::Advice;
use backend::fs::types::Advice;

/// `posix_fadvise(fd, offset, len, advice)`—Declares an expected access
/// pattern for a file.
Expand Down
2 changes: 1 addition & 1 deletion src/fs/fcntl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub fn fcntl_get_seals<Fd: AsFd>(fd: Fd) -> io::Result<SealFlags> {
}

#[cfg(any(linux_kernel, target_os = "freebsd", target_os = "fuchsia"))]
pub use backend::fs::types::SealFlags;
use backend::fs::types::SealFlags;

/// `fcntl(fd, F_ADD_SEALS)`
///
Expand Down
4 changes: 1 addition & 3 deletions src/fs/fcopyfile.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
use crate::fs::CopyfileFlags;
use crate::{backend, io};
use backend::fd::AsFd;

/// `copyfile_state_t`
pub use backend::fs::types::copyfile_state_t;
use backend::fs::types::copyfile_state_t;

/// `fcopyfile(from, to, state, flags)`
///
Expand Down
27 changes: 13 additions & 14 deletions src/fs/fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ use crate::fs::{Gid, Uid};
use crate::fs::{OFlags, SeekFrom, Timespec};
use crate::{backend, io};
use backend::fd::{AsFd, BorrowedFd};

#[cfg(not(any(target_os = "espidf", target_os = "vita", target_os = "wasi")))]
pub use backend::fs::types::FlockOperation;

#[cfg(not(any(
netbsdlike,
solarish,
Expand All @@ -21,10 +17,17 @@ pub use backend::fs::types::FlockOperation;
target_os = "redox",
target_os = "vita",
)))]
pub use backend::fs::types::FallocateFlags;

pub use backend::fs::types::Stat;

use backend::fs::types::FallocateFlags;
#[cfg(not(any(
target_os = "espidf",
target_os = "solaris",
target_os = "vita",
target_os = "wasi"
)))]
use backend::fs::types::FlockOperation;
#[cfg(linux_kernel)]
use backend::fs::types::FsWord;
use backend::fs::types::Stat;
#[cfg(not(any(
solarish,
target_os = "espidf",
Expand All @@ -35,13 +38,9 @@ pub use backend::fs::types::Stat;
target_os = "vita",
target_os = "wasi",
)))]
pub use backend::fs::types::StatFs;

use backend::fs::types::StatFs;
#[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "wasi")))]
pub use backend::fs::types::{StatVfs, StatVfsMountFlags};

#[cfg(linux_kernel)]
pub use backend::fs::types::FsWord;
use backend::fs::types::StatVfs;

/// Timestamps used by [`utimensat`] and [`futimens`].
///
Expand Down
4 changes: 0 additions & 4 deletions src/fs/file_type.rs

This file was deleted.

3 changes: 1 addition & 2 deletions src/fs/memfd_create.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::fd::OwnedFd;
use crate::{backend, io, path};

pub use backend::fs::types::MemfdFlags;
use backend::fs::types::MemfdFlags;

/// `memfd_create(path, flags)`
///
Expand Down
12 changes: 5 additions & 7 deletions src/fs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ mod fcntl_apple;
#[cfg(apple)]
mod fcopyfile;
pub(crate) mod fd;
mod file_type;
#[cfg(apple)]
mod getpath;
#[cfg(not(target_os = "wasi"))] // WASI doesn't have get[gpu]id.
mod id;
#[cfg(not(target_os = "wasi"))]
#[cfg(linux_kernel)]
mod ioctl;
#[cfg(not(any(
target_os = "espidf",
Expand Down Expand Up @@ -90,19 +89,18 @@ pub use dir::{Dir, DirEntry};
target_os = "redox",
target_os = "vita",
)))]
pub use fadvise::{fadvise, Advice};
pub use fadvise::fadvise;
pub use fcntl::*;
#[cfg(apple)]
pub use fcntl_apple::*;
#[cfg(apple)]
pub use fcopyfile::*;
pub use fd::*;
pub use file_type::FileType;
#[cfg(apple)]
pub use getpath::getpath;
#[cfg(not(target_os = "wasi"))]
pub use id::*;
#[cfg(not(target_os = "wasi"))]
#[cfg(linux_kernel)]
pub use ioctl::*;
#[cfg(not(any(
target_os = "espidf",
Expand All @@ -113,7 +111,7 @@ pub use ioctl::*;
)))]
pub use makedev::*;
#[cfg(any(linux_kernel, target_os = "freebsd"))]
pub use memfd_create::{memfd_create, MemfdFlags};
pub use memfd_create::memfd_create;
#[cfg(linux_kernel)]
#[cfg(feature = "fs")]
pub use mount::*;
Expand All @@ -125,7 +123,7 @@ pub use seek_from::SeekFrom;
#[cfg(target_os = "linux")]
pub use sendfile::sendfile;
#[cfg(linux_kernel)]
pub use statx::{statx, Statx, StatxFlags, StatxTimestamp};
pub use statx::statx;
#[cfg(not(any(
target_os = "espidf",
target_os = "redox",
Expand Down
3 changes: 1 addition & 2 deletions src/fs/statx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
use crate::fd::AsFd;
use crate::fs::AtFlags;
use crate::{backend, io, path};

pub use backend::fs::types::{Statx, StatxFlags, StatxTimestamp};
use backend::fs::types::{Statx, StatxFlags};

#[cfg(feature = "linux_4_11")]
use backend::fs::syscalls::statx as _statx;
Expand Down
3 changes: 2 additions & 1 deletion src/ioctl/patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::backend::c;
use crate::io::Result;

use core::marker::PhantomData;
use core::ptr::addr_of_mut;
use core::{fmt, mem};

/// Implements an `ioctl` with no real arguments.
Expand Down Expand Up @@ -144,7 +145,7 @@ unsafe impl<Opcode: CompileTimeOpcode, Input> Ioctl for Setter<Opcode, Input> {
const OPCODE: self::Opcode = Opcode::OPCODE;

fn as_ptr(&mut self) -> *mut c::c_void {
&mut self.input as *mut Input as *mut c::c_void
addr_of_mut!(self.input).cast::<c::c_void>()
}

unsafe fn output_from_ptr(_: IoctlOutput, _: *mut c::c_void) -> Result<Self::Output> {
Expand Down
8 changes: 6 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,12 @@
// It is common in Linux and libc APIs for types to vary between platforms.
#![allow(clippy::useless_conversion)]
// Redox and WASI have enough differences that it isn't worth precisely
// conditionalizing all the `use`s for them.
#![cfg_attr(any(target_os = "redox", target_os = "wasi"), allow(unused_imports))]
// conditionalizing all the `use`s for them. Similar for if we don't have
// "all-apis".
#![cfg_attr(
any(target_os = "redox", target_os = "wasi", not(feature = "all-apis")),
allow(unused_imports)
)]

#[cfg(all(feature = "alloc", not(feature = "rustc-dep-of-std")))]
extern crate alloc;
Expand Down
1 change: 1 addition & 0 deletions src/maybe_polyfill/no_std/net/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod ip_addr;
mod socket_addr;

#[allow(unused_imports)]
pub use self::ip_addr::{IpAddr, Ipv4Addr, Ipv6Addr, Ipv6MulticastScope};
pub use self::socket_addr::{SocketAddr, SocketAddrV4, SocketAddrV6};

0 comments on commit 3f338d8

Please sign in to comment.