Skip to content

Commit 39c6366

Browse files
bors[bot]asomers
andauthored
Merge #1507 #1508
1507: Forbid dead code again r=asomers a=asomers The old problems with bitflags no longer apply 1508: More rust docs r=asomers a=asomers Switch from allow(missing_docs) to deny(missing_docs), which should gradually help us moving forward. Also, add a few missing docs, such as for sched and aio. Co-authored-by: Alan Somers <asomers@gmail.com>
3 parents 48fbce9 + 5039222 + 8cc140e commit 39c6366

File tree

8 files changed

+102
-13
lines changed

8 files changed

+102
-13
lines changed

src/env.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Environment variables
12
use cfg_if::cfg_if;
23
use std::fmt;
34

src/lib.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@
55
#![crate_name = "nix"]
66
#![cfg(unix)]
77
#![allow(non_camel_case_types)]
8-
// latest bitflags triggers a rustc bug with cross-crate macro expansions causing dead_code
9-
// warnings even though the macro expands into something with allow(dead_code)
10-
#![allow(dead_code)]
118
#![cfg_attr(test, deny(warnings))]
129
#![recursion_limit = "500"]
1310
#![deny(unused)]
1411
#![deny(unstable_features)]
1512
#![deny(missing_copy_implementations)]
1613
#![deny(missing_debug_implementations)]
14+
#![deny(missing_docs)]
1715

1816
// Re-exported external crates
1917
pub use libc;
@@ -23,13 +21,14 @@ pub use libc;
2321

2422
// Public crates
2523
#[cfg(not(target_os = "redox"))]
24+
#[allow(missing_docs)]
2625
pub mod dir;
2726
pub mod env;
27+
#[allow(missing_docs)]
2828
pub mod errno;
29-
#[deny(missing_docs)]
3029
pub mod features;
30+
#[allow(missing_docs)]
3131
pub mod fcntl;
32-
#[deny(missing_docs)]
3332
#[cfg(any(target_os = "android",
3433
target_os = "dragonfly",
3534
target_os = "freebsd",
@@ -42,6 +41,7 @@ pub mod fcntl;
4241
pub mod ifaddrs;
4342
#[cfg(any(target_os = "android",
4443
target_os = "linux"))]
44+
#[allow(missing_docs)]
4545
pub mod kmod;
4646
#[cfg(any(target_os = "android",
4747
target_os = "freebsd",
@@ -52,23 +52,24 @@ pub mod mount;
5252
target_os = "fushsia",
5353
target_os = "linux",
5454
target_os = "netbsd"))]
55+
#[allow(missing_docs)]
5556
pub mod mqueue;
56-
#[deny(missing_docs)]
5757
#[cfg(not(target_os = "redox"))]
5858
pub mod net;
59-
#[deny(missing_docs)]
6059
pub mod poll;
61-
#[deny(missing_docs)]
6260
#[cfg(not(any(target_os = "redox", target_os = "fuchsia")))]
6361
pub mod pty;
6462
pub mod sched;
6563
pub mod sys;
64+
#[allow(missing_docs)]
6665
pub mod time;
6766
// This can be implemented for other platforms as soon as libc
6867
// provides bindings for them.
6968
#[cfg(all(target_os = "linux",
7069
any(target_arch = "x86", target_arch = "x86_64")))]
70+
#[allow(missing_docs)]
7171
pub mod ucontext;
72+
#[allow(missing_docs)]
7273
pub mod unistd;
7374

7475
/*
@@ -101,11 +102,17 @@ pub type Result<T> = result::Result<T, Errno>;
101102
/// ones.
102103
pub type Error = Errno;
103104

105+
/// Common trait used to represent file system paths by many Nix functions.
104106
pub trait NixPath {
107+
/// Is the path empty?
105108
fn is_empty(&self) -> bool;
106109

110+
/// Length of the path in bytes
107111
fn len(&self) -> usize;
108112

113+
/// Execute a function with this path as a `CStr`.
114+
///
115+
/// Mostly used internally by Nix.
109116
fn with_nix_path<T, F>(&self, f: F) -> Result<T>
110117
where F: FnOnce(&CStr) -> T;
111118
}

src/mount/bsd.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ impl<'a> Nmount<'a> {
347347
self
348348
}
349349

350+
/// Create a new `Nmount` struct with no options
350351
pub fn new() -> Self {
351352
Self::default()
352353
}

src/mount/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
//! Mount file systems
12
#[cfg(any(target_os = "android", target_os = "linux"))]
3+
#[allow(missing_docs)]
24
mod linux;
35

46
#[cfg(any(target_os = "android", target_os = "linux"))]
7+
#[allow(missing_docs)]
58
pub use self::linux::*;
69

710
#[cfg(any(target_os = "dragonfly",

src/sched.rs

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//! Execution scheduling
2+
//!
3+
//! See Also
4+
//! [sched.h](https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sched.h.html)
15
use crate::{Errno, Result};
26

37
#[cfg(any(target_os = "android", target_os = "linux"))]
@@ -16,33 +20,70 @@ mod sched_linux_like {
1620
// For some functions taking with a parameter of type CloneFlags,
1721
// only a subset of these flags have an effect.
1822
libc_bitflags! {
23+
/// Options for use with [`clone`]
1924
pub struct CloneFlags: c_int {
25+
/// The calling process and the child process run in the same
26+
/// memory space.
2027
CLONE_VM;
28+
/// The caller and the child process share the same filesystem
29+
/// information.
2130
CLONE_FS;
31+
/// The calling process and the child process share the same file
32+
/// descriptor table.
2233
CLONE_FILES;
34+
/// The calling process and the child process share the same table
35+
/// of signal handlers.
2336
CLONE_SIGHAND;
37+
/// If the calling process is being traced, then trace the child
38+
/// also.
2439
CLONE_PTRACE;
40+
/// The execution of the calling process is suspended until the
41+
/// child releases its virtual memory resources via a call to
42+
/// execve(2) or _exit(2) (as with vfork(2)).
2543
CLONE_VFORK;
44+
/// The parent of the new child (as returned by getppid(2))
45+
/// will be the same as that of the calling process.
2646
CLONE_PARENT;
47+
/// The child is placed in the same thread group as the calling
48+
/// process.
2749
CLONE_THREAD;
50+
/// The cloned child is started in a new mount namespace.
2851
CLONE_NEWNS;
52+
/// The child and the calling process share a single list of System
53+
/// V semaphore adjustment values
2954
CLONE_SYSVSEM;
30-
CLONE_SETTLS;
31-
CLONE_PARENT_SETTID;
32-
CLONE_CHILD_CLEARTID;
55+
// Not supported by Nix due to lack of varargs support in Rust FFI
56+
// CLONE_SETTLS;
57+
// Not supported by Nix due to lack of varargs support in Rust FFI
58+
// CLONE_PARENT_SETTID;
59+
// Not supported by Nix due to lack of varargs support in Rust FFI
60+
// CLONE_CHILD_CLEARTID;
61+
/// Unused since Linux 2.6.2
62+
#[deprecated(since = "0.23.0", note = "Deprecated by Linux 2.6.2")]
3363
CLONE_DETACHED;
64+
/// A tracing process cannot force `CLONE_PTRACE` on this child
65+
/// process.
3466
CLONE_UNTRACED;
35-
CLONE_CHILD_SETTID;
67+
// Not supported by Nix due to lack of varargs support in Rust FFI
68+
// CLONE_CHILD_SETTID;
69+
/// Create the process in a new cgroup namespace.
3670
CLONE_NEWCGROUP;
71+
/// Create the process in a new UTS namespace.
3772
CLONE_NEWUTS;
73+
/// Create the process in a new IPC namespace.
3874
CLONE_NEWIPC;
75+
/// Create the process in a new user namespace.
3976
CLONE_NEWUSER;
77+
/// Create the process in a new PID namespace.
4078
CLONE_NEWPID;
79+
/// Create the process in a new network namespace.
4180
CLONE_NEWNET;
81+
/// The new process shares an I/O context with the calling process.
4282
CLONE_IO;
4383
}
4484
}
4585

86+
/// Type for the function executed by [`clone`].
4687
pub type CloneCb<'a> = Box<dyn FnMut() -> isize + 'a>;
4788

4889
/// CpuSet represent a bit-mask of CPUs.
@@ -212,12 +253,18 @@ mod sched_linux_like {
212253
Errno::result(res).map(Pid::from_raw)
213254
}
214255

256+
/// disassociate parts of the process execution context
257+
///
258+
/// See also [unshare(2)](https://man7.org/linux/man-pages/man2/unshare.2.html)
215259
pub fn unshare(flags: CloneFlags) -> Result<()> {
216260
let res = unsafe { libc::unshare(flags.bits()) };
217261

218262
Errno::result(res).map(drop)
219263
}
220264

265+
/// reassociate thread with a namespace
266+
///
267+
/// See also [setns(2)](https://man7.org/linux/man-pages/man2/setns.2.html)
221268
pub fn setns(fd: RawFd, nstype: CloneFlags) -> Result<()> {
222269
let res = unsafe { libc::setns(fd, nstype.bits()) };
223270

src/sys/aio.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,11 @@ libc_enum! {
6060
#[repr(i32)]
6161
#[non_exhaustive]
6262
pub enum LioOpcode {
63+
/// No operation
6364
LIO_NOP,
65+
/// Write data as if by a call to [`aio_write`]
6466
LIO_WRITE,
67+
/// Write data as if by a call to [`aio_read`]
6568
LIO_READ,
6669
}
6770
}
@@ -840,6 +843,7 @@ unsafe impl<'a> Sync for LioCb<'a> {}
840843

841844
#[cfg(not(any(target_os = "ios", target_os = "macos")))]
842845
impl<'a> LioCb<'a> {
846+
/// Are no [`AioCb`]s contained?
843847
pub fn is_empty(&self) -> bool {
844848
self.aiocbs.is_empty()
845849
}

src/sys/mod.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! Mostly platform-specific functionality
12
#[cfg(any(target_os = "dragonfly",
23
target_os = "freebsd",
34
target_os = "ios",
@@ -7,6 +8,7 @@
78
pub mod aio;
89

910
#[cfg(any(target_os = "android", target_os = "linux"))]
11+
#[allow(missing_docs)]
1012
pub mod epoll;
1113

1214
#[cfg(any(target_os = "dragonfly",
@@ -15,9 +17,11 @@ pub mod epoll;
1517
target_os = "macos",
1618
target_os = "netbsd",
1719
target_os = "openbsd"))]
20+
#[allow(missing_docs)]
1821
pub mod event;
1922

2023
#[cfg(any(target_os = "android", target_os = "linux"))]
24+
#[allow(missing_docs)]
2125
pub mod eventfd;
2226

2327
#[cfg(any(target_os = "android",
@@ -34,14 +38,18 @@ pub mod eventfd;
3438
pub mod ioctl;
3539

3640
#[cfg(target_os = "linux")]
41+
#[allow(missing_docs)]
3742
pub mod memfd;
3843

3944
#[cfg(not(target_os = "redox"))]
45+
#[allow(missing_docs)]
4046
pub mod mman;
4147

4248
#[cfg(target_os = "linux")]
49+
#[allow(missing_docs)]
4350
pub mod personality;
4451

52+
#[allow(missing_docs)]
4553
pub mod pthread;
4654

4755
#[cfg(any(target_os = "android",
@@ -51,35 +59,44 @@ pub mod pthread;
5159
target_os = "macos",
5260
target_os = "netbsd",
5361
target_os = "openbsd"))]
62+
#[allow(missing_docs)]
5463
pub mod ptrace;
5564

5665
#[cfg(target_os = "linux")]
5766
pub mod quota;
5867

5968
#[cfg(any(target_os = "linux"))]
69+
#[allow(missing_docs)]
6070
pub mod reboot;
6171

6272
#[cfg(not(any(target_os = "redox", target_os = "fuchsia", target_os = "illumos")))]
73+
#[allow(missing_docs)]
6374
pub mod resource;
6475

6576
#[cfg(not(target_os = "redox"))]
77+
#[allow(missing_docs)]
6678
pub mod select;
6779

6880
#[cfg(any(target_os = "android",
6981
target_os = "freebsd",
7082
target_os = "ios",
7183
target_os = "linux",
7284
target_os = "macos"))]
85+
#[allow(missing_docs)]
7386
pub mod sendfile;
7487

88+
#[allow(missing_docs)]
7589
pub mod signal;
7690

7791
#[cfg(any(target_os = "android", target_os = "linux"))]
92+
#[allow(missing_docs)]
7893
pub mod signalfd;
7994

8095
#[cfg(not(target_os = "redox"))]
96+
#[allow(missing_docs)]
8197
pub mod socket;
8298

99+
#[allow(missing_docs)]
83100
pub mod stat;
84101

85102
#[cfg(any(target_os = "android",
@@ -90,25 +107,34 @@ pub mod stat;
90107
target_os = "macos",
91108
target_os = "openbsd"
92109
))]
110+
#[allow(missing_docs)]
93111
pub mod statfs;
94112

95113
pub mod statvfs;
96114

97115
#[cfg(any(target_os = "android", target_os = "linux"))]
116+
#[allow(missing_docs)]
98117
pub mod sysinfo;
99118

119+
#[allow(missing_docs)]
100120
pub mod termios;
101121

122+
#[allow(missing_docs)]
102123
pub mod time;
103124

125+
#[allow(missing_docs)]
104126
pub mod uio;
105127

128+
#[allow(missing_docs)]
106129
pub mod utsname;
107130

131+
#[allow(missing_docs)]
108132
pub mod wait;
109133

110134
#[cfg(any(target_os = "android", target_os = "linux"))]
135+
#[allow(missing_docs)]
111136
pub mod inotify;
112137

113138
#[cfg(target_os = "linux")]
139+
#[allow(missing_docs)]
114140
pub mod timerfd;

src/sys/signal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Portions of this file are Copyright 2014 The Rust Project Developers.
22
// See https://www.rust-lang.org/policies/licenses.
33

4-
///! Operating system signals.
4+
//! Operating system signals.
55
66
use crate::{Error, Result};
77
use crate::errno::Errno;

0 commit comments

Comments
 (0)