Skip to content

Commit cc673a1

Browse files
authored
Improve comments and documentation. (#1332)
1 parent 4d062ac commit cc673a1

Some content is hidden

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

54 files changed

+207
-151
lines changed

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ targets = [
110110
default = ["std", "use-libc-auxv"]
111111

112112
# This enables use of std. Disabling this enables `#![no_std]`, and requires
113-
# Rust 1.64 or newer.
113+
# Rust 1.77 or newer.
114114
std = ["bitflags/std", "alloc", "libc?/std", "libc_errno?/std"]
115115

116116
# Enable this to request the libc backend.
@@ -172,6 +172,9 @@ system = ["linux-raw-sys/system"]
172172
runtime = ["linux-raw-sys/prctl"]
173173

174174
# Enable all API features.
175+
#
176+
# This is primarily intended for rustix developers. Users are encouraged to
177+
# enable only those features they need.
175178
all-apis = [
176179
"event",
177180
"fs",

src/backend/libc/fs/dir.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,9 @@ impl DirEntry {
330330
&self.name
331331
}
332332

333-
/// Returns the "offset" of this directory entry. Note that this is not
334-
/// a true numerical offset but an opaque cookie that identifies a
335-
/// position in the given stream.
333+
/// Returns the offset of this directory entry. This is not a true
334+
/// numerical offset but an opaque cookie that identifies a position in the
335+
/// given stream.
336336
#[cfg(any(
337337
linux_like,
338338
solarish,

src/backend/libc/fs/syscalls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2267,7 +2267,7 @@ fn times_to_attrlist(times: &Timestamps) -> io::Result<(c::size_t, [c::timespec;
22672267
#[cfg(apple)]
22682268
type Attrgroup = u32;
22692269

2270-
/// Attribute list for use with `setattrlist`.
2270+
/// Attribute list for use with [`setattrlist`].
22712271
#[cfg(apple)]
22722272
#[repr(C)]
22732273
struct Attrlist {

src/backend/libc/fs/types.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,16 +332,17 @@ bitflags! {
332332

333333
/// `O_LARGEFILE`
334334
///
335-
/// Note that rustix and/or libc will automatically set this flag when appropriate on
336-
/// `open(2)` and friends, thus typical users do not need to care about it.
337-
/// It will may be reported in return of `fcntl_getfl`, though.
335+
/// Rustix and/or libc will automatically set this flag when
336+
/// appropriate in the [`rustix::fs::open`] family of functions, so
337+
/// typical users do not need to care about it. It may be reported in
338+
/// the return of `fcntl_getfl`, though.
338339
#[cfg(any(linux_kernel, solarish))]
339340
const LARGEFILE = bitcast!(c::O_LARGEFILE);
340341

341342
/// `O_ASYNC`, `FASYNC`
342343
///
343-
/// Note that this flag can't be used with [`rustix::fs::open`] family of functions, use
344-
/// [`rustix::fs::fcntl_setfl`] instead
344+
/// This flag can't be used with the [`rustix::fs::open`] family of
345+
/// functions, use [`rustix::fs::fcntl_setfl`] instead.
345346
#[cfg(not(any(
346347
target_os = "aix",
347348
target_os = "espidf",
@@ -994,7 +995,7 @@ pub type StatFs = c::statfs;
994995
#[cfg(linux_like)]
995996
pub type StatFs = c::statfs64;
996997

997-
/// `fsid_t` for use with `StatFs`.
998+
/// `fsid_t` for use with [`StatFs`].
998999
#[cfg(not(any(
9991000
solarish,
10001001
target_os = "espidf",

src/backend/libc/mount/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ pub(crate) enum FsConfigCmd {
147147
/// `FSCONFIG_CMD_RECONFIGURE`
148148
Reconfigure = 7,
149149

150-
/// `FSCONFIG_CMD_CREATE_EXCL`
150+
/// `FSCONFIG_CMD_CREATE_EXCL` (since Linux 6.6)
151151
CreateExclusive = 8,
152152
}
153153

src/backend/libc/net/addr.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,8 @@ impl SocketAddrUnix {
7979
/// Construct a new unnamed address.
8080
///
8181
/// The kernel will assign an abstract Unix-domain address to the socket
82-
/// when you call [`bind_unix()`][crate::net::bind_unix]. You can
83-
/// inspect the assigned name with
84-
/// [`getsockname`][crate::net::getsockname].
82+
/// when you call [`bind`][crate::net::bind]. You can inspect the assigned
83+
/// name with [`getsockname`][crate::net::getsockname].
8584
///
8685
/// # References
8786
/// - [Linux]
@@ -238,6 +237,9 @@ impl fmt::Debug for SocketAddrUnix {
238237
}
239238

240239
/// `struct sockaddr_storage`.
240+
///
241+
/// This type is guaranteed to be large enough to hold any encoded socket
242+
/// address.
241243
#[repr(transparent)]
242244
#[derive(Copy, Clone)]
243245
pub struct SocketAddrStorage(c::sockaddr_storage);

src/backend/libc/net/read_sockaddr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub(crate) unsafe fn read_sa_family(storage: *const c::sockaddr) -> u16 {
101101
#[cfg(apple)]
102102
#[inline]
103103
unsafe fn read_sun_path0(storage: *const c::sockaddr) -> u8 {
104-
// In `read_ss_family` we assert that we know the layout of `sockaddr`.
104+
// In `read_sa_family` we assert that we know the layout of `sockaddr`.
105105
storage
106106
.cast::<u8>()
107107
.add(super::addr::offsetof_sun_path())

src/backend/libc/net/sockopt.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,8 +1086,8 @@ pub(crate) fn xdp_mmap_offsets(fd: BorrowedFd<'_>) -> io::Result<XdpMmapOffsets>
10861086
getsockopt_raw(fd, c::SOL_XDP, c::XDP_MMAP_OFFSETS, &mut value, &mut optlen)?;
10871087

10881088
if optlen as usize == size_of::<c::xdp_mmap_offsets_v1>() {
1089-
// Safety: All members of xdp_mmap_offsets are u64 and thus are correctly
1090-
// initialized by `MaybeUninit::<xdp_statistics>::zeroed()`
1089+
// SAFETY: All members of xdp_mmap_offsets are `u64` and thus are
1090+
// correctly initialized by `MaybeUninit::<xdp_statistics>::zeroed()`.
10911091
let xpd_mmap_offsets = unsafe { value.assume_init() };
10921092
Ok(XdpMmapOffsets {
10931093
rx: XdpRingOffset {
@@ -1121,8 +1121,8 @@ pub(crate) fn xdp_mmap_offsets(fd: BorrowedFd<'_>) -> io::Result<XdpMmapOffsets>
11211121
size_of::<xdp_mmap_offsets>(),
11221122
"unexpected getsockopt size"
11231123
);
1124-
// Safety: All members of xdp_mmap_offsets are u64 and thus are correctly
1125-
// initialized by `MaybeUninit::<xdp_statistics>::zeroed()`
1124+
// SAFETY: All members of xdp_mmap_offsets are `u64` and thus are
1125+
// correctly initialized by `MaybeUninit::<xdp_statistics>::zeroed()`
11261126
let xpd_mmap_offsets = unsafe { value.assume_init() };
11271127
Ok(XdpMmapOffsets {
11281128
rx: XdpRingOffset {
@@ -1165,8 +1165,8 @@ pub(crate) fn xdp_statistics(fd: BorrowedFd<'_>) -> io::Result<XdpStatistics> {
11651165
getsockopt_raw(fd, c::SOL_XDP, c::XDP_STATISTICS, &mut value, &mut optlen)?;
11661166

11671167
if optlen as usize == size_of::<xdp_statistics_v1>() {
1168-
// Safety: All members of xdp_statistics are u64 and thus are correctly
1169-
// initialized by `MaybeUninit::<xdp_statistics>::zeroed()`
1168+
// SAFETY: All members of xdp_statistics are `u64` and thus are
1169+
// correctly initialized by `MaybeUninit::<xdp_statistics>::zeroed()`.
11701170
let xdp_statistics = unsafe { value.assume_init() };
11711171
Ok(XdpStatistics {
11721172
rx_dropped: xdp_statistics.rx_dropped,
@@ -1182,8 +1182,8 @@ pub(crate) fn xdp_statistics(fd: BorrowedFd<'_>) -> io::Result<XdpStatistics> {
11821182
size_of::<xdp_statistics>(),
11831183
"unexpected getsockopt size"
11841184
);
1185-
// Safety: All members of xdp_statistics are u64 and thus are correctly
1186-
// initialized by `MaybeUninit::<xdp_statistics>::zeroed()`
1185+
// SAFETY: All members of xdp_statistics are `u64` and thus are
1186+
// correctly initialized by `MaybeUninit::<xdp_statistics>::zeroed()`.
11871187
let xdp_statistics = unsafe { value.assume_init() };
11881188
Ok(XdpStatistics {
11891189
rx_dropped: xdp_statistics.rx_dropped,

src/backend/libc/system/syscalls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub(crate) fn setdomainname(name: &[u8]) -> io::Result<()> {
8383
}
8484
}
8585

86-
// https://github.com/rust-lang/libc/pull/4212
86+
// <https://github.com/rust-lang/libc/pull/4212>
8787
#[cfg(target_os = "android")]
8888
pub(crate) fn setdomainname(name: &[u8]) -> io::Result<()> {
8989
syscall! {

src/backend/libc/termios/types.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Types for the `termios` module.
2+
13
#![allow(non_camel_case_types)]
24

35
#[cfg(not(target_os = "redox"))]

src/backend/linux_raw/arch/mips64r6.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
//! MIPS-family platforms have a special calling convention for `__NR_pipe`,
88
//! however we use `__NR_pipe2` instead to avoid having to implement it.
99
//!
10-
//! Note that MIPS R6 inline assembly currently doesn't differ from MIPS,
11-
//! because no explicit call of R6-only or R2-only instructions exist here.
10+
//! MIPS R6 inline assembly currently doesn't differ from MIPS, because no
11+
//! explicit call of R6-only or R2-only instructions exist here.
1212
1313
use crate::backend::reg::{
1414
ArgReg, FromAsm, RetReg, SyscallNumber, ToAsm, A0, A1, A2, A3, A4, A5, R0,

src/backend/linux_raw/fs/dir.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl Dir {
8787
///
8888
/// [`libc::seekdir`]: https://docs.rs/libc/latest/arm-unknown-linux-gnueabihf/libc/fn.seekdir.html
8989
// In the linux_raw backend here, we don't use `libc::seekdir` and don't
90-
// have this limitattion, but it's a goal of rustix to support the same API
90+
// have this limitation, but it's a goal of rustix to support the same API
9191
// on both the linux_raw and libc backends.
9292
#[cfg(target_pointer_width = "64")]
9393
#[cfg_attr(docsrs, doc(cfg(target_pointer_width = "64")))]
@@ -315,9 +315,9 @@ impl DirEntry {
315315
&self.name
316316
}
317317

318-
/// Returns the "offset" of this directory entry. Note that this is not
319-
/// a true numerical offset but an opaque cookie that identifies a
320-
/// position in the given stream.
318+
/// Returns the offset of this directory entry. This is not a true
319+
/// numerical offset but an opaque cookie that identifies a position in the
320+
/// given stream.
321321
#[inline]
322322
pub fn offset(&self) -> i64 {
323323
self.d_off

src/backend/linux_raw/fs/types.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,15 +252,16 @@ bitflags! {
252252

253253
/// `O_LARGEFILE`
254254
///
255-
/// Note that rustix and/or libc will automatically set this flag when appropriate on
256-
/// `open(2)` and friends, thus typical users do not need to care about it.
257-
/// It will may be reported in return of `fcntl_getfl`, though.
255+
/// Tustix and/or libc will automatically set this flag when
256+
/// appropriate in the [`rustix::fs::open`] family of functions, so
257+
/// typical users do not need to care about it. It may be reported in
258+
/// the return of `fcntl_getfl`, though.
258259
const LARGEFILE = linux_raw_sys::general::O_LARGEFILE;
259260

260261
/// `O_ASYNC`, `FASYNC`
261262
///
262-
/// Note that this flag can't be used with [`rustix::fs::open`] family of functions, use
263-
/// [`rustix::fs::fcntl_setfl`] instead
263+
/// This flag can't be used with the [`rustix::fs::open`] family of
264+
/// functions, use [`rustix::fs::fcntl_setfl`] instead.
264265
const ASYNC = linux_raw_sys::general::FASYNC;
265266

266267
/// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags>

src/backend/linux_raw/mount/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ pub(crate) enum FsConfigCmd {
144144
/// `FSCONFIG_CMD_RECONFIGURE`
145145
Reconfigure = linux_raw_sys::general::fsconfig_command::FSCONFIG_CMD_RECONFIGURE as u32,
146146

147-
/// `FSCONFIG_CMD_CREATE_EXCL`
147+
/// `FSCONFIG_CMD_CREATE_EXCL` (since Linux 6.6)
148148
CreateExclusive = linux_raw_sys::general::fsconfig_command::FSCONFIG_CMD_CREATE_EXCL as u32,
149149
}
150150

src/backend/linux_raw/net/addr.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,8 @@ impl SocketAddrUnix {
6767
/// Construct a new unnamed address.
6868
///
6969
/// The kernel will assign an abstract Unix-domain address to the socket
70-
/// when you call [`bind_unix()`][crate::net::bind_unix]. You can
71-
/// inspect the assigned name with
72-
/// [`getsockname`][crate::net::getsockname].
70+
/// when you call [`bind`][crate::net::bind]. You can inspect the assigned
71+
/// name with [`getsockname`][crate::net::getsockname].
7372
///
7473
/// # References
7574
/// - [Linux]
@@ -189,6 +188,9 @@ impl fmt::Debug for SocketAddrUnix {
189188
}
190189

191190
/// `struct sockaddr_storage`.
191+
///
192+
/// This type is guaranteed to be large enough to hold any encoded socket
193+
/// address.
192194
#[repr(transparent)]
193195
#[derive(Copy, Clone)]
194196
pub struct SocketAddrStorage(c::sockaddr_storage);

src/backend/linux_raw/net/sockopt.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -892,8 +892,8 @@ pub(crate) fn xdp_mmap_offsets(fd: BorrowedFd<'_>) -> io::Result<XdpMmapOffsets>
892892
getsockopt_raw(fd, c::SOL_XDP, c::XDP_MMAP_OFFSETS, &mut value, &mut optlen)?;
893893

894894
if optlen as usize == size_of::<c::xdp_mmap_offsets_v1>() {
895-
// Safety: All members of xdp_mmap_offsets are u64 and thus are correctly
896-
// initialized by `MaybeUninit::<xdp_statistics>::zeroed()`
895+
// SAFETY: All members of xdp_mmap_offsets are `u64` and thus are
896+
// correctly initialized by `MaybeUninit::<xdp_statistics>::zeroed()`.
897897
let xpd_mmap_offsets = unsafe { value.assume_init() };
898898
Ok(XdpMmapOffsets {
899899
rx: XdpRingOffset {
@@ -927,8 +927,8 @@ pub(crate) fn xdp_mmap_offsets(fd: BorrowedFd<'_>) -> io::Result<XdpMmapOffsets>
927927
size_of::<xdp_mmap_offsets>(),
928928
"unexpected getsockopt size"
929929
);
930-
// Safety: All members of xdp_mmap_offsets are u64 and thus are correctly
931-
// initialized by `MaybeUninit::<xdp_statistics>::zeroed()`
930+
// SAFETY: All members of xdp_mmap_offsets are `u64` and thus are
931+
// correctly initialized by `MaybeUninit::<xdp_statistics>::zeroed()`.
932932
let xpd_mmap_offsets = unsafe { value.assume_init() };
933933
Ok(XdpMmapOffsets {
934934
rx: XdpRingOffset {
@@ -971,8 +971,8 @@ pub(crate) fn xdp_statistics(fd: BorrowedFd<'_>) -> io::Result<XdpStatistics> {
971971
getsockopt_raw(fd, c::SOL_XDP, c::XDP_STATISTICS, &mut value, &mut optlen)?;
972972

973973
if optlen as usize == size_of::<xdp_statistics_v1>() {
974-
// Safety: All members of xdp_statistics are u64 and thus are correctly
975-
// initialized by `MaybeUninit::<xdp_statistics>::zeroed()`
974+
// SAFETY: All members of xdp_statistics are `u64` and thus are
975+
// correctly initialized by `MaybeUninit::<xdp_statistics>::zeroed()`.
976976
let xdp_statistics = unsafe { value.assume_init() };
977977
Ok(XdpStatistics {
978978
rx_dropped: xdp_statistics.rx_dropped,
@@ -988,8 +988,8 @@ pub(crate) fn xdp_statistics(fd: BorrowedFd<'_>) -> io::Result<XdpStatistics> {
988988
size_of::<xdp_statistics>(),
989989
"unexpected getsockopt size"
990990
);
991-
// Safety: All members of xdp_statistics are u64 and thus are correctly
992-
// initialized by `MaybeUninit::<xdp_statistics>::zeroed()`
991+
// SAFETY: All members of xdp_statistics are `u64` and thus are
992+
// correctly initialized by `MaybeUninit::<xdp_statistics>::zeroed()`.
993993
let xdp_statistics = unsafe { value.assume_init() };
994994
Ok(XdpStatistics {
995995
rx_dropped: xdp_statistics.rx_dropped,

src/backend/linux_raw/param/auxv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ unsafe fn init_from_aux_iter(aux_iter: impl Iterator<Item = Elf_auxv_t>) -> Opti
399399
AT_SYSINFO_EHDR => sysinfo_ehdr = check_elf_base(a_val as *mut _)?.as_ptr(),
400400

401401
AT_BASE => {
402-
// The `AT_BASE` value can be NULL in a static executable that
402+
// The `AT_BASE` value can be null in a static executable that
403403
// doesn't use a dynamic linker. If so, ignore it.
404404
if !a_val.is_null() {
405405
let _ = check_elf_base(a_val.cast())?;

src/backend/linux_raw/termios/types.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
//! Types for the `termios` module.
2+
13
#![allow(non_camel_case_types)]
24

35
use crate::ffi;
46

5-
// We don't want to use tcflag_t directly so we don't expose linux_raw_sys
6-
// publicly. It appears to be c_ulong on SPARC and c_uint everywhere else.
7+
// We don't want to use `tcflag_t` directly so we don't expose linux_raw_sys
8+
// publicly. It appears to be `c_ulong `on SPARC and `c_uint` everywhere else.
79

810
#[cfg(target_arch = "sparc")]
911
pub type tcflag_t = ffi::c_ulong;

src/bitcast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ macro_rules! bitcast {
1313
0
1414
} else if false {
1515
// Ensure that the source and destinations are the same size.
16-
// SAFETY: This code is under an `if false`.
1716
#[allow(
1817
unsafe_code,
1918
unused_unsafe,
2019
clippy::useless_transmute,
2120
clippy::missing_transmute_annotations
2221
)]
22+
// SAFETY: This code is under an `if false`.
2323
unsafe {
2424
::core::mem::transmute($x)
2525
}

src/event/epoll.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ pub fn create(flags: epoll::CreateFlags) -> io::Result<OwnedFd> {
107107
/// This registers interest in any of the events set in `event_flags` occurring
108108
/// on the file descriptor associated with `data`.
109109
///
110-
/// Note that `close`ing a file descriptor does not necessarily unregister
111-
/// interest which can lead to spurious events being returned from
112-
/// [`epoll::wait`]. If a file descriptor is an `Arc<dyn SystemResource>`, then
113-
/// `epoll` can be thought to maintain a `Weak<dyn SystemResource>` to the file
114-
/// descriptor. Check the [faq] for details.
110+
/// `close`ing a file descriptor does not necessarily unregister interest which
111+
/// can lead to spurious events being returned from [`epoll::wait`]. If a file
112+
/// descriptor is an `Arc<dyn SystemResource>`, then `epoll` can be thought to
113+
/// maintain a `Weak<dyn SystemResource>` to the file descriptor. Check the
114+
/// [faq] for details.
115115
///
116116
/// # References
117117
/// - [Linux]
@@ -205,7 +205,8 @@ pub fn delete<EpollFd: AsFd, SourceFd: AsFd>(epoll: EpollFd, source: SourceFd) -
205205
/// [Linux]: https://man7.org/linux/man-pages/man2/epoll_wait.2.html
206206
/// [illumos]: https://www.illumos.org/man/3C/epoll_wait
207207
#[cfg(feature = "alloc")]
208-
#[cfg_attr(docsrs, doc(cfg(feature = "alloc"), alias = "epoll_wait"))]
208+
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
209+
#[doc(alias = "epoll_wait")]
209210
#[inline]
210211
pub fn wait<EpollFd: AsFd>(
211212
epoll: EpollFd,

src/event/pause.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::backend;
22

3-
/// `pause()`
3+
/// `pause()`—Sleep until interrupted by a signal.
44
///
55
/// The POSIX `pause` interface returns an error code, but the only thing
66
/// `pause` does is sleep until interrupted by a signal, so it always

src/event/select.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ pub struct FdSetElement(pub(crate) usize);
9696
///
9797
/// # Safety
9898
///
99-
/// All fds in in all the sets must correspond to open file descriptors.
99+
/// All fds in all the sets must correspond to open file descriptors.
100100
///
101101
/// # References
102102
/// - [POSIX]

0 commit comments

Comments
 (0)