Skip to content

Commit 126112c

Browse files
Merge #1854
1854: Reformat everything r=rtzoeller a=SUPERCILEX Unfortunately, #1748 didn't do the trick because of rust-lang/rustfmt#3253. This PR fully enforces global formatting. Closes #770 Co-authored-by: Alex Saveau <[email protected]>
2 parents 20df092 + 58f9994 commit 126112c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2541
-1428
lines changed

.cirrus.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,4 +315,4 @@ task:
315315
container:
316316
image: rust:latest
317317
setup_script: rustup +$TOOLCHAIN component add rustfmt
318-
test_script: $TOOL +$TOOLCHAIN fmt --all -- --check
318+
test_script: $TOOL +$TOOLCHAIN fmt --all -- --check **/*.rs

src/dir.rs

+39-22
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
//! List directory contents
22
3-
use crate::{Error, NixPath, Result};
43
use crate::errno::Errno;
54
use crate::fcntl::{self, OFlag};
6-
use std::os::unix::io::{AsRawFd, IntoRawFd, RawFd};
7-
use std::ptr;
8-
use std::ffi;
95
use crate::sys;
6+
use crate::{Error, NixPath, Result};
107
use cfg_if::cfg_if;
8+
use std::ffi;
9+
use std::os::unix::io::{AsRawFd, IntoRawFd, RawFd};
10+
use std::ptr;
1111

1212
#[cfg(target_os = "linux")]
1313
use libc::{dirent64 as dirent, readdir64_r as readdir_r};
@@ -29,21 +29,26 @@ use libc::{dirent, readdir_r};
2929
/// * returns entries' names as a `CStr` (no allocation or conversion beyond whatever libc
3030
/// does).
3131
#[derive(Debug, Eq, Hash, PartialEq)]
32-
pub struct Dir(
33-
ptr::NonNull<libc::DIR>
34-
);
32+
pub struct Dir(ptr::NonNull<libc::DIR>);
3533

3634
impl Dir {
3735
/// Opens the given path as with `fcntl::open`.
38-
pub fn open<P: ?Sized + NixPath>(path: &P, oflag: OFlag,
39-
mode: sys::stat::Mode) -> Result<Self> {
36+
pub fn open<P: ?Sized + NixPath>(
37+
path: &P,
38+
oflag: OFlag,
39+
mode: sys::stat::Mode,
40+
) -> Result<Self> {
4041
let fd = fcntl::open(path, oflag, mode)?;
4142
Dir::from_fd(fd)
4243
}
4344

4445
/// Opens the given path as with `fcntl::openat`.
45-
pub fn openat<P: ?Sized + NixPath>(dirfd: RawFd, path: &P, oflag: OFlag,
46-
mode: sys::stat::Mode) -> Result<Self> {
46+
pub fn openat<P: ?Sized + NixPath>(
47+
dirfd: RawFd,
48+
path: &P,
49+
oflag: OFlag,
50+
mode: sys::stat::Mode,
51+
) -> Result<Self> {
4752
let fd = fcntl::openat(dirfd, path, oflag, mode)?;
4853
Dir::from_fd(fd)
4954
}
@@ -57,11 +62,13 @@ impl Dir {
5762
/// Converts from a file descriptor, closing it on success or failure.
5863
#[doc(alias("fdopendir"))]
5964
pub fn from_fd(fd: RawFd) -> Result<Self> {
60-
let d = ptr::NonNull::new(unsafe { libc::fdopendir(fd) }).ok_or_else(|| {
61-
let e = Error::last();
62-
unsafe { libc::close(fd) };
63-
e
64-
})?;
65+
let d = ptr::NonNull::new(unsafe { libc::fdopendir(fd) }).ok_or_else(
66+
|| {
67+
let e = Error::last();
68+
unsafe { libc::close(fd) };
69+
e
70+
},
71+
)?;
6572
Ok(Dir(d))
6673
}
6774

@@ -103,9 +110,11 @@ fn next(dir: &mut Dir) -> Option<Result<Entry>> {
103110
// Probably fine here too then.
104111
let mut ent = std::mem::MaybeUninit::<dirent>::uninit();
105112
let mut result = ptr::null_mut();
106-
if let Err(e) = Errno::result(
107-
readdir_r(dir.0.as_ptr(), ent.as_mut_ptr(), &mut result))
108-
{
113+
if let Err(e) = Errno::result(readdir_r(
114+
dir.0.as_ptr(),
115+
ent.as_mut_ptr(),
116+
&mut result,
117+
)) {
109118
return Some(Err(e));
110119
}
111120
if result.is_null() {
@@ -207,7 +216,7 @@ pub enum Type {
207216

208217
impl Entry {
209218
/// Returns the inode number (`d_ino`) of the underlying `dirent`.
210-
#[allow(clippy::useless_conversion)] // Not useless on all OSes
219+
#[allow(clippy::useless_conversion)] // Not useless on all OSes
211220
// The cast is not unnecessary on all platforms.
212221
#[allow(clippy::unnecessary_cast)]
213222
pub fn ino(&self) -> u64 {
@@ -240,7 +249,11 @@ impl Entry {
240249
/// notably, some Linux filesystems don't implement this. The caller should use `stat` or
241250
/// `fstat` if this returns `None`.
242251
pub fn file_type(&self) -> Option<Type> {
243-
#[cfg(not(any(target_os = "illumos", target_os = "solaris", target_os = "haiku")))]
252+
#[cfg(not(any(
253+
target_os = "illumos",
254+
target_os = "solaris",
255+
target_os = "haiku"
256+
)))]
244257
match self.0.d_type {
245258
libc::DT_FIFO => Some(Type::Fifo),
246259
libc::DT_CHR => Some(Type::CharacterDevice),
@@ -253,7 +266,11 @@ impl Entry {
253266
}
254267

255268
// illumos, Solaris, and Haiku systems do not have the d_type member at all:
256-
#[cfg(any(target_os = "illumos", target_os = "solaris", target_os = "haiku"))]
269+
#[cfg(any(
270+
target_os = "illumos",
271+
target_os = "solaris",
272+
target_os = "haiku"
273+
))]
257274
None
258275
}
259276
}

src/features.rs

+21-19
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@ pub use self::os::*;
33

44
#[cfg(any(target_os = "linux", target_os = "android"))]
55
mod os {
6-
use std::os::unix::ffi::OsStrExt;
76
use crate::sys::utsname::uname;
87
use crate::Result;
8+
use std::os::unix::ffi::OsStrExt;
99

1010
// Features:
1111
// * atomic cloexec on socket: 2.6.27
1212
// * pipe2: 2.6.27
1313
// * accept4: 2.6.28
1414

1515
static VERS_UNKNOWN: usize = 1;
16-
static VERS_2_6_18: usize = 2;
17-
static VERS_2_6_27: usize = 3;
18-
static VERS_2_6_28: usize = 4;
19-
static VERS_3: usize = 5;
16+
static VERS_2_6_18: usize = 2;
17+
static VERS_2_6_27: usize = 3;
18+
static VERS_2_6_28: usize = 4;
19+
static VERS_3: usize = 5;
2020

2121
#[inline]
2222
fn digit(dst: &mut usize, b: u8) {
@@ -27,7 +27,7 @@ mod os {
2727
fn parse_kernel_version() -> Result<usize> {
2828
let u = uname()?;
2929

30-
let mut curr: usize = 0;
30+
let mut curr: usize = 0;
3131
let mut major: usize = 0;
3232
let mut minor: usize = 0;
3333
let mut patch: usize = 0;
@@ -41,13 +41,11 @@ mod os {
4141
b'.' | b'-' => {
4242
curr += 1;
4343
}
44-
b'0'..=b'9' => {
45-
match curr {
46-
0 => digit(&mut major, b),
47-
1 => digit(&mut minor, b),
48-
_ => digit(&mut patch, b),
49-
}
50-
}
44+
b'0'..=b'9' => match curr {
45+
0 => digit(&mut major, b),
46+
1 => digit(&mut minor, b),
47+
_ => digit(&mut patch, b),
48+
},
5149
_ => break,
5250
}
5351
}
@@ -87,7 +85,9 @@ mod os {
8785

8886
/// Check if the OS supports atomic close-on-exec for sockets
8987
pub fn socket_atomic_cloexec() -> bool {
90-
kernel_version().map(|version| version >= VERS_2_6_27).unwrap_or(false)
88+
kernel_version()
89+
.map(|version| version >= VERS_2_6_27)
90+
.unwrap_or(false)
9191
}
9292

9393
#[test]
@@ -111,11 +111,13 @@ mod os {
111111
}
112112
}
113113

114-
#[cfg(any(target_os = "macos",
115-
target_os = "ios",
116-
target_os = "fuchsia",
117-
target_os = "haiku",
118-
target_os = "solaris"))]
114+
#[cfg(any(
115+
target_os = "macos",
116+
target_os = "ios",
117+
target_os = "fuchsia",
118+
target_os = "haiku",
119+
target_os = "solaris"
120+
))]
119121
mod os {
120122
/// Check if the OS supports atomic close-on-exec for sockets
121123
pub const fn socket_atomic_cloexec() -> bool {

src/ifaddrs.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ use std::iter::Iterator;
99
use std::mem;
1010
use std::option::Option;
1111

12-
use crate::{Result, Errno};
13-
use crate::sys::socket::{SockaddrLike, SockaddrStorage};
1412
use crate::net::if_::*;
13+
use crate::sys::socket::{SockaddrLike, SockaddrStorage};
14+
use crate::{Errno, Result};
1515

1616
/// Describes a single address for an interface as returned by `getifaddrs`.
1717
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
@@ -47,7 +47,8 @@ impl InterfaceAddress {
4747
fn from_libc_ifaddrs(info: &libc::ifaddrs) -> InterfaceAddress {
4848
let ifname = unsafe { ffi::CStr::from_ptr(info.ifa_name) };
4949
let address = unsafe { SockaddrStorage::from_raw(info.ifa_addr, None) };
50-
let netmask = unsafe { SockaddrStorage::from_raw(info.ifa_netmask, None) };
50+
let netmask =
51+
unsafe { SockaddrStorage::from_raw(info.ifa_netmask, None) };
5152
let mut addr = InterfaceAddress {
5253
interface_name: ifname.to_string_lossy().to_string(),
5354
flags: InterfaceFlags::from_bits_truncate(info.ifa_flags as i32),

src/kmod.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ libc_bitflags!(
7979
/// ```
8080
///
8181
/// See [`man init_module(2)`](https://man7.org/linux/man-pages/man2/init_module.2.html) for more information.
82-
pub fn finit_module<T: AsRawFd>(fd: &T, param_values: &CStr, flags: ModuleInitFlags) -> Result<()> {
82+
pub fn finit_module<T: AsRawFd>(
83+
fd: &T,
84+
param_values: &CStr,
85+
flags: ModuleInitFlags,
86+
) -> Result<()> {
8387
let res = unsafe {
8488
libc::syscall(
8589
libc::SYS_finit_module,
@@ -116,7 +120,9 @@ libc_bitflags!(
116120
///
117121
/// See [`man delete_module(2)`](https://man7.org/linux/man-pages/man2/delete_module.2.html) for more information.
118122
pub fn delete_module(name: &CStr, flags: DeleteModuleFlags) -> Result<()> {
119-
let res = unsafe { libc::syscall(libc::SYS_delete_module, name.as_ptr(), flags.bits()) };
123+
let res = unsafe {
124+
libc::syscall(libc::SYS_delete_module, name.as_ptr(), flags.bits())
125+
};
120126

121127
Errno::result(res).map(drop)
122128
}

0 commit comments

Comments
 (0)