Skip to content

Commit ebf7505

Browse files
committed
Merge #837
837: More cleanups and enable some more compiler lints r=asomers a=Susurrus Gonna run this through CI and see what breaks on non-Linux-x64 platforms. These changes are minor cleanups, but improve our doc story and should help with future submitted PRs.
2 parents 899eff7 + 3406b1b commit ebf7505

28 files changed

+175
-143
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@ This project adheres to [Semantic Versioning](http://semver.org/).
88
### Added
99

1010
### Changed
11+
- Display and Debug for SysControlAddr now includes all fields.
12+
([#837](https://github.com/nix-rust/nix/pull/837))
1113

1214
### Fixed
15+
- Properly exposed 460800 and 921600 baud rates on NetBSD
16+
([#837](https://github.com/nix-rust/nix/pull/837))
1317

1418
### Removed
1519

src/fcntl.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ libc_bitflags!(
205205
}
206206
);
207207

208+
#[allow(missing_debug_implementations)]
208209
pub enum FcntlArg<'a> {
209210
F_DUPFD(RawFd),
210211
F_DUPFD_CLOEXEC(RawFd),
@@ -230,7 +231,7 @@ pub enum FcntlArg<'a> {
230231
#[cfg(any(target_os = "linux", target_os = "android"))]
231232
F_GETPIPE_SZ,
232233
#[cfg(any(target_os = "linux", target_os = "android"))]
233-
F_SETPIPE_SZ(libc::c_int),
234+
F_SETPIPE_SZ(c_int),
234235

235236
// TODO: Rest of flags
236237
}
@@ -267,6 +268,8 @@ pub fn fcntl(fd: RawFd, arg: FcntlArg) -> Result<c_int> {
267268
Errno::result(res)
268269
}
269270

271+
#[derive(Clone, Copy)]
272+
#[allow(missing_debug_implementations)]
270273
pub enum FlockArg {
271274
LockShared,
272275
LockExclusive,
@@ -343,7 +346,7 @@ pub fn vmsplice(fd: RawFd, iov: &[IoVec<&[u8]>], flags: SpliceFFlags) -> Result<
343346
#[cfg(any(target_os = "linux"))]
344347
libc_bitflags!(
345348
/// Mode argument flags for fallocate determining operation performed on a given range.
346-
pub struct FallocateFlags: libc::c_int {
349+
pub struct FallocateFlags: c_int {
347350
/// File size is not changed.
348351
///
349352
/// offset + len can be greater than file size.

src/features.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Feature tests for OS functionality
12
pub use self::os::*;
23

34
#[cfg(any(target_os = "linux", target_os = "android"))]
@@ -82,6 +83,7 @@ mod os {
8283
}
8384
}
8485

86+
/// Check if the OS supports atomic close-on-exec for sockets
8587
pub fn socket_atomic_cloexec() -> bool {
8688
kernel_version() >= VERS_2_6_27
8789
}
@@ -94,6 +96,7 @@ mod os {
9496

9597
#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly", target_os = "ios", target_os = "openbsd", target_os = "netbsd"))]
9698
mod os {
99+
/// Check if the OS supports atomic close-on-exec for sockets
97100
pub fn socket_atomic_cloexec() -> bool {
98101
false
99102
}

src/lib.rs

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,61 +10,52 @@
1010
#![allow(dead_code)]
1111
#![cfg_attr(test, deny(warnings))]
1212
#![recursion_limit = "500"]
13+
#![deny(unused)]
14+
#![deny(unstable_features)]
15+
#![deny(missing_copy_implementations)]
16+
#![deny(missing_debug_implementations)]
1317

18+
// External crates
1419
extern crate bytes;
1520
#[macro_use]
1621
extern crate bitflags;
17-
1822
#[macro_use]
1923
extern crate cfg_if;
2024
extern crate void;
2125

22-
#[macro_use] mod macros;
23-
26+
// Re-exported external crates
2427
pub extern crate libc;
2528

26-
use errno::Errno;
29+
// Private internal modules
30+
#[macro_use] mod macros;
2731

32+
// Public crates
2833
pub mod errno;
34+
#[deny(missing_docs)]
2935
pub mod features;
3036
pub mod fcntl;
31-
3237
#[cfg(any(target_os = "linux", target_os = "android"))]
3338
pub mod mount;
34-
3539
#[cfg(any(target_os = "dragonfly",
3640
target_os = "freebsd",
3741
target_os = "fushsia",
3842
target_os = "linux",
3943
target_os = "netbsd"))]
4044
pub mod mqueue;
41-
42-
pub mod pty;
43-
44-
pub mod poll;
45-
45+
#[deny(missing_docs)]
4646
pub mod net;
47-
48-
#[cfg(any(target_os = "dragonfly",
49-
target_os = "freebsd",
50-
target_os = "ios",
51-
target_os = "linux",
52-
target_os = "macos",
53-
target_os = "netbsd",
54-
target_os = "openbsd"))]
55-
pub mod ifaddrs;
56-
47+
#[deny(missing_docs)]
48+
pub mod poll;
49+
#[deny(missing_docs)]
50+
pub mod pty;
5751
#[cfg(any(target_os = "linux", target_os = "android"))]
5852
pub mod sched;
59-
6053
pub mod sys;
61-
6254
// This can be implemented for other platforms as soon as libc
6355
// provides bindings for them.
6456
#[cfg(all(target_os = "linux",
6557
any(target_arch = "x86", target_arch = "x86_64")))]
6658
pub mod ucontext;
67-
6859
pub mod unistd;
6960

7061
/*
@@ -73,14 +64,14 @@ pub mod unistd;
7364
*
7465
*/
7566

76-
use libc::c_char;
77-
use std::{ptr, result};
67+
use libc::{c_char, PATH_MAX};
68+
69+
use std::{error, fmt, ptr, result};
7870
use std::ffi::{CStr, OsStr};
79-
use std::path::{Path, PathBuf};
8071
use std::os::unix::ffi::OsStrExt;
81-
use std::fmt;
82-
use std::error;
83-
use libc::PATH_MAX;
72+
use std::path::{Path, PathBuf};
73+
74+
use errno::Errno;
8475

8576
/// Nix Result Type
8677
pub type Result<T> = result::Result<T, Error>;
@@ -94,7 +85,7 @@ pub type Result<T> = result::Result<T, Error>;
9485
/// implementing other common traits.
9586
#[derive(Clone, Copy, Debug, PartialEq)]
9687
pub enum Error {
97-
Sys(errno::Errno),
88+
Sys(Errno),
9889
InvalidPath,
9990
/// The operation involved a conversion to Rust's native String type, which failed because the
10091
/// string did not contain all valid UTF-8.

src/mqueue.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ libc_bitflags!{
3030

3131
#[repr(C)]
3232
#[derive(Clone, Copy)]
33+
#[allow(missing_debug_implementations)]
3334
pub struct MqAttr {
3435
mq_attr: libc::mq_attr,
3536
}

src/net/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Functionality involving network interfaces
12
// To avoid clashing with the keyword "if", we use "if_" as the module name.
23
// The original header is called "net/if.h".
34
pub mod if_;

src/poll.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Wait for events to trigger on specific file descriptors
12
#[cfg(any(target_os = "android", target_os = "dragonfly", target_os = "freebsd", target_os = "linux"))]
23
use sys::time::TimeSpec;
34
#[cfg(any(target_os = "android", target_os = "dragonfly", target_os = "freebsd", target_os = "linux"))]
@@ -18,6 +19,7 @@ use errno::Errno;
1819
/// retrieved by calling [`revents()`](#method.revents) on the `PollFd`.
1920
#[repr(C)]
2021
#[derive(Clone, Copy)]
22+
#[allow(missing_debug_implementations)]
2123
pub struct PollFd {
2224
pollfd: libc::pollfd,
2325
}

src/pty.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ use errno::Errno;
1717
///
1818
/// This is returned by `openpty`. Note that this type does *not* implement `Drop`, so the user
1919
/// must manually close the file descriptors.
20+
#[derive(Clone, Copy)]
21+
#[allow(missing_debug_implementations)]
2022
pub struct OpenptyResult {
23+
/// The master port in a virtual pty pair
2124
pub master: RawFd,
25+
/// The slave port in a virtual pty pair
2226
pub slave: RawFd,
2327
}
2428

src/sched.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use ::unistd::Pid;
99
// For some functions taking with a parameter of type CloneFlags,
1010
// only a subset of these flags have an effect.
1111
libc_bitflags!{
12-
pub struct CloneFlags: libc::c_int {
12+
pub struct CloneFlags: c_int {
1313
CLONE_VM;
1414
CLONE_FS;
1515
CLONE_FILES;
@@ -40,6 +40,7 @@ pub type CloneCb<'a> = Box<FnMut() -> isize + 'a>;
4040

4141
#[repr(C)]
4242
#[derive(Clone, Copy)]
43+
#[allow(missing_debug_implementations)]
4344
pub struct CpuSet {
4445
cpu_set: libc::cpu_set_t,
4546
}

src/sys/aio.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ impl<'a> AioCb<'a> {
295295
aiocb: a,
296296
mutable: true,
297297
in_progress: false,
298-
buffer: Buffer::Phantom(PhantomData)
298+
buffer: Buffer::Phantom(PhantomData),
299299
}
300300
}
301301

@@ -379,7 +379,7 @@ impl<'a> AioCb<'a> {
379379
aiocb: a,
380380
mutable: false,
381381
in_progress: false,
382-
buffer: Buffer::Bytes(buf2)
382+
buffer: Buffer::Bytes(buf2),
383383
}
384384
}
385385

@@ -464,7 +464,7 @@ impl<'a> AioCb<'a> {
464464
aiocb: a,
465465
mutable: true,
466466
in_progress: false,
467-
buffer: Buffer::BytesMut(buf2)
467+
buffer: Buffer::BytesMut(buf2),
468468
}
469469
}
470470

@@ -619,7 +619,7 @@ impl<'a> AioCb<'a> {
619619
aiocb: a,
620620
mutable: false,
621621
in_progress: false,
622-
buffer: Buffer::None
622+
buffer: Buffer::None,
623623
}
624624
}
625625

src/sys/epoll.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::mem;
77
use ::Error;
88

99
libc_bitflags!(
10-
pub struct EpollFlags: libc::c_int {
10+
pub struct EpollFlags: c_int {
1111
EPOLLIN;
1212
EPOLLPRI;
1313
EPOLLOUT;
@@ -42,6 +42,7 @@ libc_bitflags!{
4242
}
4343
}
4444

45+
#[allow(missing_debug_implementations)]
4546
#[derive(Clone, Copy)]
4647
#[repr(C)]
4748
pub struct EpollEvent {
@@ -58,7 +59,7 @@ impl EpollEvent {
5859
}
5960

6061
pub fn events(&self) -> EpollFlags {
61-
EpollFlags::from_bits(self.event.events as libc::c_int).unwrap()
62+
EpollFlags::from_bits(self.event.events as c_int).unwrap()
6263
}
6364

6465
pub fn data(&self) -> u64 {

src/sys/event.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use std::mem;
1414
// Redefine kevent in terms of programmer-friendly enums and bitfields.
1515
#[derive(Clone, Copy)]
1616
#[repr(C)]
17+
#[allow(missing_debug_implementations)]
1718
pub struct KEvent {
1819
kevent: libc::kevent,
1920
}
@@ -24,7 +25,7 @@ pub struct KEvent {
2425
type type_of_udata = *mut libc::c_void;
2526
#[cfg(any(target_os = "dragonfly", target_os = "freebsd",
2627
target_os = "ios", target_os = "macos"))]
27-
type type_of_data = libc::intptr_t;
28+
type type_of_data = intptr_t;
2829
#[cfg(any(target_os = "netbsd"))]
2930
type type_of_udata = intptr_t;
3031
#[cfg(any(target_os = "netbsd", target_os = "openbsd"))]

src/sys/mman.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
use {Error, Result, NixPath};
1+
use {Error, Result};
2+
#[cfg(not(target_os = "android"))]
3+
use NixPath;
24
use errno::Errno;
5+
#[cfg(not(target_os = "android"))]
36
use fcntl::OFlag;
47
use libc::{self, c_int, c_void, size_t, off_t};
8+
#[cfg(not(target_os = "android"))]
59
use sys::stat::Mode;
610
use std::os::unix::io::RawFd;
711

812
libc_bitflags!{
913
/// Desired memory protection of a memory mapping.
10-
pub struct ProtFlags: libc::c_int {
14+
pub struct ProtFlags: c_int {
1115
/// Pages cannot be accessed.
1216
PROT_NONE;
1317
/// Pages can be read.

0 commit comments

Comments
 (0)