Skip to content

Commit 94ba12b

Browse files
authored
Miscellaneous documentaion cleanups. (#1365)
1 parent dbeae3c commit 94ba12b

Some content is hidden

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

49 files changed

+240
-170
lines changed

ci/select-setsize.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ From Dan Gohman <[email protected]>
22
Subject: [PATCH] Remove the `FD_SETSIZE` limitation in `select`
33

44
The `fd_set` type is limited to a fixed `FD_SETSIZE` number of file
5-
descriptors, however Linux's `select has no such limitation. Change
5+
descriptors, however Linux's `select` has no such limitation. Change
66
the `select` implementation to using manual bit-vector logic to better
77
implement the Linux semantics.
88

examples/kq.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ fn main() -> std::io::Result<()> {
4141
Event::new(
4242
EventFilter::Timer {
4343
ident: 0,
44-
timer: Some(core::time::Duration::from_secs(1)),
44+
timer: Some(std::time::Duration::from_secs(1)),
4545
},
4646
EventFlags::ADD,
4747
null_mut(),
4848
),
4949
Event::new(
5050
EventFilter::Timer {
5151
ident: 1,
52-
timer: Some(core::time::Duration::from_secs(2)),
52+
timer: Some(std::time::Duration::from_secs(2)),
5353
},
5454
EventFlags::ADD | EventFlags::ONESHOT,
5555
null_mut(),

examples/process.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! A command which prints out information about the process it runs in.
22
3-
#[cfg(all(feature = "process", feature = "param"))]
3+
#[cfg(all(feature = "process", feature = "param", feature = "system"))]
44
#[cfg(not(windows))]
55
fn main() -> rustix::io::Result<()> {
66
#[cfg(not(target_os = "espidf"))]
@@ -88,7 +88,10 @@ fn main() -> rustix::io::Result<()> {
8888
Ok(())
8989
}
9090

91-
#[cfg(any(windows, not(all(feature = "process", feature = "param"))))]
91+
#[cfg(any(
92+
windows,
93+
not(all(feature = "process", feature = "param", feature = "system"))
94+
))]
9295
fn main() -> Result<(), &'static str> {
93-
Err("This example requires --features=process,param and is not supported on Windows.")
96+
Err("This example requires --features=process,param,system and is not supported on Windows.")
9497
}

src/backend/libc/event/syscalls.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,19 @@ use core::mem::MaybeUninit;
3535
use core::ptr::null;
3636
#[cfg(any(bsd, linux_kernel, solarish, target_os = "redox", target_os = "wasi"))]
3737
use core::ptr::null_mut;
38-
#[cfg(any(
39-
linux_kernel,
40-
solarish,
41-
target_os = "redox",
42-
all(feature = "alloc", bsd)
43-
))]
38+
#[cfg(any(bsd, linux_kernel, solarish, target_os = "redox"))]
4439
use {crate::backend::conv::borrowed_fd, crate::fd::BorrowedFd};
4540
#[cfg(any(
41+
bsd,
4642
linux_kernel,
4743
solarish,
4844
target_os = "freebsd",
4945
target_os = "illumos",
5046
target_os = "espidf",
51-
target_os = "redox",
52-
all(feature = "alloc", bsd)
47+
target_os = "redox"
5348
))]
5449
use {crate::backend::conv::ret_owned_fd, crate::fd::OwnedFd};
55-
#[cfg(all(feature = "alloc", bsd))]
50+
#[cfg(bsd)]
5651
use {crate::event::kqueue::Event, crate::utils::as_ptr};
5752

5853
#[cfg(any(
@@ -91,12 +86,12 @@ pub(crate) fn eventfd(initval: u32, flags: EventfdFlags) -> io::Result<OwnedFd>
9186
}
9287
}
9388

94-
#[cfg(all(feature = "alloc", bsd))]
89+
#[cfg(bsd)]
9590
pub(crate) fn kqueue() -> io::Result<OwnedFd> {
9691
unsafe { ret_owned_fd(c::kqueue()) }
9792
}
9893

99-
#[cfg(all(feature = "alloc", bsd))]
94+
#[cfg(bsd)]
10095
pub(crate) unsafe fn kevent(
10196
kq: BorrowedFd<'_>,
10297
changelist: &[Event],

src/backend/libc/net/read_sockaddr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ pub(crate) unsafe fn sockaddr_nonempty(storage: *const c::sockaddr, len: SocketA
127127
return false;
128128
}
129129

130-
// On macOS, if we get an `AF_UNIX` with an empty path, treat it as
131-
// an absent address.
130+
// On macOS, if we get an `AF_UNIX` with an empty path, treat it as an
131+
// absent address.
132132
#[cfg(apple)]
133133
if family == c::AF_UNIX && read_sun_path0(storage) == 0 {
134134
return false;

src/backend/libc/termios/types.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
#[cfg(not(target_os = "redox"))]
66
use crate::ffi;
77

8-
// We don't want to use tcflag_t directly so we don't expose libc
9-
// publicly. Redox uses u32, apple uses c_ulong, everything else
10-
// seems to use c_uint.
8+
// We don't want to use `tcflag_t` directly so we don't expose libc
9+
// publicly. Redox uses `u32`, apple uses `c_ulong`, everything else
10+
// seems to use `c_uint`.
1111

1212
#[cfg(apple)]
1313
pub type tcflag_t = ffi::c_ulong;

src/backend/libc/winsock_c.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ pub(crate) type c_long = i32;
2121
pub(crate) type c_ulong = u32;
2222
pub(crate) use core::ffi::c_void;
2323

24-
// windows-sys declares these constants as u16. For better compatibility
25-
// with Unix-family APIs, redeclare them as u32.
24+
// windows-sys declares these constants as `u16`. For better compatibility with
25+
// Unix-family APIs, redeclare them as `i32`.
2626
pub(crate) const AF_INET: i32 = WinSock::AF_INET as _;
2727
pub(crate) const AF_INET6: i32 = WinSock::AF_INET6 as _;
2828
pub(crate) const AF_UNSPEC: i32 = WinSock::AF_UNSPEC as _;

src/backend/linux_raw/fs/dir.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ impl Dir {
176176
let name = name.to_owned();
177177
assert!(name.as_bytes().len() <= self.buf.len() - name_start);
178178

179-
// Do an unaligned u64 load for `d_ino`.
179+
// Do an unaligned `u64` load for `d_ino`.
180180
let d_ino = u64::from_ne_bytes([
181181
self.buf[pos + offsetof_d_ino],
182182
self.buf[pos + offsetof_d_ino + 1],
@@ -188,7 +188,7 @@ impl Dir {
188188
self.buf[pos + offsetof_d_ino + 7],
189189
]);
190190

191-
// Do an unaligned i64 load for `d_off`
191+
// Do an unaligned `i64` load for `d_off`.
192192
let d_off = i64::from_ne_bytes([
193193
self.buf[pos + offsetof_d_off],
194194
self.buf[pos + offsetof_d_off + 1],

src/backend/linux_raw/mm/syscalls.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,9 @@ pub(crate) fn mlockall(flags: MlockAllFlags) -> io::Result<()> {
226226
// because if a load happens and evokes a fault before the `mlockall`,
227227
// the memory doesn't get locked, but if the load and therefore
228228
// the fault happens after, then the memory does get locked.
229-
// So to be conservative in this regard, we use `syscall` instead
230-
// of `syscall_readonly`
229+
//
230+
// So to be conservative in this regard, we use `syscall` instead of
231+
// `syscall_readonly`
231232
unsafe { ret(syscall!(__NR_mlockall, flags)) }
232233
}
233234

src/buffer.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use core::slice;
1212
/// There are three types that implement the `Buffer` trait, and the type you
1313
/// use determines the return type of the functions that use it:
1414
///
15-
/// | If you pass a... | You get back a... |
16-
/// | ------------------------ | ----------------- |
15+
/// | If you pass a | You get back a |
16+
/// | ------------------------ | --------------- |
1717
/// | `&mut [u8]` | `usize`, indicating the number of elements initialized. |
1818
/// | `&mut [MaybeUninit<u8>]` | `(&mut [u8], &[mut MaybeUninit<u8>])`, holding the initialized and uninitialized subslices. |
1919
/// | [`SpareCapacity`] | `usize`, indicating the number of elements initialized. And the `Vec` is extended. |
@@ -35,7 +35,7 @@ use core::slice;
3535
///
3636
/// ```rust
3737
/// # use rustix::io::read;
38-
/// # use core::mem::MaybeUninit;
38+
/// # use std::mem::MaybeUninit;
3939
/// # fn example(fd: rustix::fd::BorrowedFd) -> rustix::io::Result<()> {
4040
/// let mut buf = [MaybeUninit::<u8>::uninit(); 64];
4141
/// let (init, uninit) = read(fd, &mut buf)?;
@@ -67,26 +67,26 @@ use core::slice;
6767
/// "cannot move out of `self` which is behind a mutable reference"
6868
/// and
6969
/// "move occurs because `x` has type `&mut [u8]`, which does not implement the `Copy` trait",
70-
/// replace `x` with `&mut *x`. See `confusing_error_buffer_wrapper` in
70+
/// replace `x` with `&mut *x`. See `error_buffer_wrapper` in
7171
/// examples/buffer_errors.rs.
7272
///
7373
/// If you see errors like
7474
/// "type annotations needed"
7575
/// and
7676
/// "cannot infer type of the type parameter `Buf` declared on the function `read`",
7777
/// you may need to change a `&mut []` to `&mut [0_u8; 0]`. See
78-
/// `confusing_error_empty_slice` in examples/buffer_errors.rs.
78+
/// `error_empty_slice` in examples/buffer_errors.rs.
7979
///
8080
/// If you see errors like
8181
/// "the trait bound `[MaybeUninit<u8>; 1]: Buffer<u8>` is not satisfied",
8282
/// add a `&mut` to pass the array by reference instead of by value. See
83-
/// `confusing_error_array_by_value` in examples/buffer_errors.rs.
83+
/// `error_array_by_value` in examples/buffer_errors.rs.
8484
///
8585
/// If you see errors like
8686
/// "cannot move out of `x`, a captured variable in an `FnMut` closure",
87-
/// try replacing `x` with `&mut *x`, or, if that doesn't work, try moving
88-
/// a `let` into the closure body. See `confusing_error_retry_closure` and
89-
/// `confusing_error_retry_indirect_closure` in examples/buffer_errors.rs.
87+
/// try replacing `x` with `&mut *x`, or, if that doesn't work, try moving a
88+
/// `let` into the closure body. See `error_retry_closure` and
89+
/// `error_retry_indirect_closure` in examples/buffer_errors.rs.
9090
pub trait Buffer<T>: private::Sealed<T> {}
9191

9292
// Implement `Buffer` for all the types that implement `Sealed`.
@@ -219,8 +219,8 @@ pub struct SpareCapacity<'a, T>(&'a mut Vec<T>);
219219
/// Construct an [`SpareCapacity`], which implements [`Buffer`].
220220
///
221221
/// This wraps a `Vec` and uses the spare capacity of the `Vec` as the buffer
222-
/// to receive data in, automatically setting the length of the `Vec` to
223-
/// include the received elements.
222+
/// to receive data in, automatically calling `set_len` on the `Vec` to set the
223+
/// length to include the received elements.
224224
///
225225
/// This uses the existing capacity, and never allocates, so the `Vec` should
226226
/// have some non-empty spare capacity!
@@ -285,6 +285,12 @@ mod private {
285285
type Output;
286286

287287
/// Return a pointer and length for this buffer.
288+
///
289+
/// It's tempting to have this return `&mut [MaybeUninit<T>]` instead,
290+
/// however that would require this function to be `unsafe`, because
291+
/// callers could use the `&mut [MaybeUninit<T>]` slice to set elements
292+
/// to `MaybeUninit::<T>::uninit()`, which would be a problem if `Self`
293+
/// is `&mut [T]` or similar.
288294
fn parts_mut(&mut self) -> (*mut T, usize);
289295

290296
/// Convert a finished buffer pointer into its result.

0 commit comments

Comments
 (0)