Skip to content

Commit 83ea2f3

Browse files
committed
Remove target_os annotations from the docs.
The reasons not to use it are: * Items that aren't built on the platform for which the docs were built won't show up in the docs. For example, if you build the docs on FreeBSD, you won't see that there's a kmod module only available for Linux. * Some items are built with different signatures on different OSes. A "target_os" annotation won't tell the reader that. * Using #[cfg(any(docsrs, target_os=...))] is not a solution, because too many items will simply throw errors when generating the documentation that way. For example, every enum value in a libc_enum! invocation and every const in a libc_bitflags! invocation. * Annotating the docs with a bunch of OS notes gives readers a false sense of security. For the reasons noted above, those annotations will be incomplete, which might deter users from checking the docs built for their platform. So I think we should carefully remove all of those annotations from the docs. However, I'm leaving in place annotations about target_env and target_arch, because we don't build docs separately for all of those combinations.
1 parent 261fcb2 commit 83ea2f3

30 files changed

+638
-36
lines changed

src/dir.rs

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::os::unix::io::{AsRawFd, IntoRawFd, RawFd};
55
use std::ptr;
66
use std::ffi;
77
use crate::sys;
8+
use cfg_if::cfg_if;
89

910
#[cfg(target_os = "linux")]
1011
use libc::{dirent64 as dirent, readdir64_r as readdir_r};
@@ -186,34 +187,24 @@ pub enum Type {
186187

187188
impl Entry {
188189
/// Returns the inode number (`d_ino`) of the underlying `dirent`.
189-
#[cfg(any(target_os = "android",
190-
target_os = "emscripten",
191-
target_os = "fuchsia",
192-
target_os = "haiku",
193-
target_os = "illumos",
194-
target_os = "ios",
195-
target_os = "l4re",
196-
target_os = "linux",
197-
target_os = "macos",
198-
target_os = "solaris"))]
199-
pub fn ino(&self) -> u64 {
200-
self.0.d_ino as u64
201-
}
202-
203-
/// Returns the inode number (`d_fileno`) of the underlying `dirent`.
204-
#[cfg(not(any(target_os = "android",
205-
target_os = "emscripten",
206-
target_os = "fuchsia",
207-
target_os = "haiku",
208-
target_os = "illumos",
209-
target_os = "ios",
210-
target_os = "l4re",
211-
target_os = "linux",
212-
target_os = "macos",
213-
target_os = "solaris")))]
214190
#[allow(clippy::useless_conversion)] // Not useless on all OSes
215191
pub fn ino(&self) -> u64 {
216-
u64::from(self.0.d_fileno)
192+
cfg_if! {
193+
if #[cfg(any(target_os = "android",
194+
target_os = "emscripten",
195+
target_os = "fuchsia",
196+
target_os = "haiku",
197+
target_os = "illumos",
198+
target_os = "ios",
199+
target_os = "l4re",
200+
target_os = "linux",
201+
target_os = "macos",
202+
target_os = "solaris"))] {
203+
self.0.d_ino as u64
204+
} else {
205+
u64::from(self.0.d_fileno)
206+
}
207+
}
217208
}
218209

219210
/// Returns the bare file name of this directory entry without any other leading path component.

src/fcntl.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,13 @@ libc_bitflags!(
5353
O_ACCMODE;
5454
/// Use alternate I/O semantics.
5555
#[cfg(target_os = "netbsd")]
56+
#[cfg_attr(docsrs, doc(cfg(all())))]
5657
O_ALT_IO;
5758
/// Open the file in append-only mode.
5859
O_APPEND;
5960
/// Generate a signal when input or output becomes possible.
6061
#[cfg(not(any(target_os = "illumos", target_os = "solaris")))]
62+
#[cfg_attr(docsrs, doc(cfg(all())))]
6163
O_ASYNC;
6264
/// Closes the file descriptor once an `execve` call is made.
6365
///
@@ -71,9 +73,11 @@ libc_bitflags!(
7173
target_os = "freebsd",
7274
target_os = "linux",
7375
target_os = "netbsd"))]
76+
#[cfg_attr(docsrs, doc(cfg(all())))]
7477
O_DIRECT;
7578
/// If the specified path isn't a directory, fail.
7679
#[cfg(not(any(target_os = "illumos", target_os = "solaris")))]
80+
#[cfg_attr(docsrs, doc(cfg(all())))]
7781
O_DIRECTORY;
7882
/// Implicitly follow each `write()` with an `fdatasync()`.
7983
#[cfg(any(target_os = "android",
@@ -82,11 +86,13 @@ libc_bitflags!(
8286
target_os = "macos",
8387
target_os = "netbsd",
8488
target_os = "openbsd"))]
89+
#[cfg_attr(docsrs, doc(cfg(all())))]
8590
O_DSYNC;
8691
/// Error out if a file was not created.
8792
O_EXCL;
8893
/// Open for execute only.
8994
#[cfg(target_os = "freebsd")]
95+
#[cfg_attr(docsrs, doc(cfg(all())))]
9096
O_EXEC;
9197
/// Open with an exclusive file lock.
9298
#[cfg(any(target_os = "dragonfly",
@@ -96,6 +102,7 @@ libc_bitflags!(
96102
target_os = "netbsd",
97103
target_os = "openbsd",
98104
target_os = "redox"))]
105+
#[cfg_attr(docsrs, doc(cfg(all())))]
99106
O_EXLOCK;
100107
/// Same as `O_SYNC`.
101108
#[cfg(any(target_os = "dragonfly",
@@ -106,30 +113,37 @@ libc_bitflags!(
106113
target_os = "netbsd",
107114
target_os = "openbsd",
108115
target_os = "redox"))]
116+
#[cfg_attr(docsrs, doc(cfg(all())))]
109117
O_FSYNC;
110118
/// Allow files whose sizes can't be represented in an `off_t` to be opened.
111119
#[cfg(any(target_os = "android", target_os = "linux"))]
120+
#[cfg_attr(docsrs, doc(cfg(all())))]
112121
O_LARGEFILE;
113122
/// Do not update the file last access time during `read(2)`s.
114123
#[cfg(any(target_os = "android", target_os = "linux"))]
124+
#[cfg_attr(docsrs, doc(cfg(all())))]
115125
O_NOATIME;
116126
/// Don't attach the device as the process' controlling terminal.
117127
#[cfg(not(target_os = "redox"))]
128+
#[cfg_attr(docsrs, doc(cfg(all())))]
118129
O_NOCTTY;
119130
/// Same as `O_NONBLOCK`.
120131
#[cfg(not(target_os = "redox"))]
132+
#[cfg_attr(docsrs, doc(cfg(all())))]
121133
O_NDELAY;
122134
/// `open()` will fail if the given path is a symbolic link.
123135
O_NOFOLLOW;
124136
/// When possible, open the file in nonblocking mode.
125137
O_NONBLOCK;
126138
/// Don't deliver `SIGPIPE`.
127139
#[cfg(target_os = "netbsd")]
140+
#[cfg_attr(docsrs, doc(cfg(all())))]
128141
O_NOSIGPIPE;
129142
/// Obtain a file descriptor for low-level access.
130143
///
131144
/// The file itself is not opened and other file operations will fail.
132145
#[cfg(any(target_os = "android", target_os = "linux", target_os = "redox"))]
146+
#[cfg_attr(docsrs, doc(cfg(all())))]
133147
O_PATH;
134148
/// Only allow reading.
135149
///
@@ -141,9 +155,11 @@ libc_bitflags!(
141155
O_RDWR;
142156
/// Similar to `O_DSYNC` but applies to `read`s instead.
143157
#[cfg(any(target_os = "linux", target_os = "netbsd", target_os = "openbsd"))]
158+
#[cfg_attr(docsrs, doc(cfg(all())))]
144159
O_RSYNC;
145160
/// Skip search permission checks.
146161
#[cfg(target_os = "netbsd")]
162+
#[cfg_attr(docsrs, doc(cfg(all())))]
147163
O_SEARCH;
148164
/// Open with a shared file lock.
149165
#[cfg(any(target_os = "dragonfly",
@@ -153,17 +169,21 @@ libc_bitflags!(
153169
target_os = "netbsd",
154170
target_os = "openbsd",
155171
target_os = "redox"))]
172+
#[cfg_attr(docsrs, doc(cfg(all())))]
156173
O_SHLOCK;
157174
/// Implicitly follow each `write()` with an `fsync()`.
158175
#[cfg(not(target_os = "redox"))]
176+
#[cfg_attr(docsrs, doc(cfg(all())))]
159177
O_SYNC;
160178
/// Create an unnamed temporary file.
161179
#[cfg(any(target_os = "android", target_os = "linux"))]
180+
#[cfg_attr(docsrs, doc(cfg(all())))]
162181
O_TMPFILE;
163182
/// Truncate an existing regular file to 0 length if it allows writing.
164183
O_TRUNC;
165184
/// Restore default TTY attributes.
166185
#[cfg(target_os = "freebsd")]
186+
#[cfg_attr(docsrs, doc(cfg(all())))]
167187
O_TTY_INIT;
168188
/// Only allow writing.
169189
///

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
//! * `zerocopy` - APIs like `sendfile` and `copy_file_range`
4141
#![crate_name = "nix"]
4242
#![cfg(unix)]
43+
#![cfg_attr(docsrs, doc(cfg(all())))]
4344
#![allow(non_camel_case_types)]
4445
#![cfg_attr(test, deny(warnings))]
4546
#![recursion_limit = "500"]

src/mount/bsd.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,36 @@ libc_bitflags!(
2020
pub struct MntFlags: c_int {
2121
/// ACL support enabled.
2222
#[cfg(any(target_os = "netbsd", target_os = "freebsd"))]
23+
#[cfg_attr(docsrs, doc(cfg(all())))]
2324
MNT_ACLS;
2425
/// All I/O to the file system should be done asynchronously.
2526
MNT_ASYNC;
2627
/// dir should instead be a file system ID encoded as “FSID:val0:val1”.
2728
#[cfg(target_os = "freebsd")]
29+
#[cfg_attr(docsrs, doc(cfg(all())))]
2830
MNT_BYFSID;
2931
/// Force a read-write mount even if the file system appears to be
3032
/// unclean.
3133
MNT_FORCE;
3234
/// GEOM journal support enabled.
3335
#[cfg(target_os = "freebsd")]
36+
#[cfg_attr(docsrs, doc(cfg(all())))]
3437
MNT_GJOURNAL;
3538
/// MAC support for objects.
3639
#[cfg(any(target_os = "macos", target_os = "freebsd"))]
40+
#[cfg_attr(docsrs, doc(cfg(all())))]
3741
MNT_MULTILABEL;
3842
/// Disable read clustering.
3943
#[cfg(any(target_os = "dragonfly", target_os = "freebsd"))]
44+
#[cfg_attr(docsrs, doc(cfg(all())))]
4045
MNT_NOCLUSTERR;
4146
/// Disable write clustering.
4247
#[cfg(any(target_os = "dragonfly", target_os = "freebsd"))]
48+
#[cfg_attr(docsrs, doc(cfg(all())))]
4349
MNT_NOCLUSTERW;
4450
/// Enable NFS version 4 ACLs.
4551
#[cfg(target_os = "freebsd")]
52+
#[cfg_attr(docsrs, doc(cfg(all())))]
4653
MNT_NFS4ACLS;
4754
/// Do not update access times.
4855
MNT_NOATIME;
@@ -52,6 +59,7 @@ libc_bitflags!(
5259
MNT_NOSUID;
5360
/// Do not follow symlinks.
5461
#[cfg(any(target_os = "dragonfly", target_os = "freebsd"))]
62+
#[cfg_attr(docsrs, doc(cfg(all())))]
5563
MNT_NOSYMFOLLOW;
5664
/// Mount read-only.
5765
MNT_RDONLY;
@@ -62,6 +70,7 @@ libc_bitflags!(
6270
///
6371
/// See [mksnap_ffs(8)](https://www.freebsd.org/cgi/man.cgi?query=mksnap_ffs)
6472
#[cfg(any(target_os = "macos", target_os = "freebsd"))]
73+
#[cfg_attr(docsrs, doc(cfg(all())))]
6574
MNT_SNAPSHOT;
6675
/// Using soft updates.
6776
#[cfg(any(
@@ -70,10 +79,12 @@ libc_bitflags!(
7079
target_os = "netbsd",
7180
target_os = "openbsd"
7281
))]
82+
#[cfg_attr(docsrs, doc(cfg(all())))]
7383
MNT_SOFTDEP;
7484
/// Directories with the SUID bit set chown new files to their own
7585
/// owner.
7686
#[cfg(any(target_os = "dragonfly", target_os = "freebsd"))]
87+
#[cfg_attr(docsrs, doc(cfg(all())))]
7788
MNT_SUIDDIR;
7889
/// All I/O to the file system should be done synchronously.
7990
MNT_SYNCHRONOUS;
@@ -83,12 +94,14 @@ libc_bitflags!(
8394
target_os = "freebsd",
8495
target_os = "netbsd"
8596
))]
97+
#[cfg_attr(docsrs, doc(cfg(all())))]
8698
MNT_UNION;
8799
/// Indicates that the mount command is being applied to an already
88100
/// mounted file system.
89101
MNT_UPDATE;
90102
/// Check vnode use counts.
91103
#[cfg(target_os = "freebsd")]
104+
#[cfg_attr(docsrs, doc(cfg(all())))]
92105
MNT_NONBUSY;
93106
}
94107
);
@@ -182,13 +195,15 @@ pub type NmountResult = std::result::Result<(), NmountError>;
182195
/// * [`nmount(2)`](https://www.freebsd.org/cgi/man.cgi?query=nmount)
183196
/// * [`nullfs(5)`](https://www.freebsd.org/cgi/man.cgi?query=nullfs)
184197
#[cfg(target_os = "freebsd")]
198+
#[cfg_attr(docsrs, doc(cfg(all())))]
185199
#[derive(Debug, Default)]
186200
pub struct Nmount<'a>{
187201
iov: Vec<IoVec<&'a [u8]>>,
188202
is_owned: Vec<bool>,
189203
}
190204

191205
#[cfg(target_os = "freebsd")]
206+
#[cfg_attr(docsrs, doc(cfg(all())))]
192207
impl<'a> Nmount<'a> {
193208
/// Add an opaque mount option.
194209
///

src/mount/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Mount file systems
22
#[cfg(any(target_os = "android", target_os = "linux"))]
3+
#[cfg_attr(docsrs, doc(cfg(all())))]
34
mod linux;
45

56
#[cfg(any(target_os = "android", target_os = "linux"))]
@@ -10,6 +11,7 @@ pub use self::linux::*;
1011
target_os = "macos",
1112
target_os = "netbsd",
1213
target_os = "openbsd"))]
14+
#[cfg_attr(docsrs, doc(cfg(all())))]
1315
mod bsd;
1416

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

src/mqueue.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ pub struct MqAttr {
3737
// x32 compatibility
3838
// See https://sourceware.org/bugzilla/show_bug.cgi?id=21279
3939
#[cfg(all(target_arch = "x86_64", target_pointer_width = "32"))]
40+
#[cfg_attr(docsrs, doc(cfg(all())))]
4041
pub type mq_attr_member_t = i64;
4142
#[cfg(not(all(target_arch = "x86_64", target_pointer_width = "32")))]
43+
#[cfg_attr(docsrs, doc(cfg(all())))]
4244
pub type mq_attr_member_t = libc::c_long;
4345

4446
impl MqAttr {

0 commit comments

Comments
 (0)