Skip to content

Commit f26edab

Browse files
authored
Miscellaneous documentation and debug output fixes. (#1390)
1 parent 7d6d3fa commit f26edab

File tree

14 files changed

+118
-37
lines changed

14 files changed

+118
-37
lines changed

examples/buffer_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ fn error_retry_closure_uninit() {
7070

7171
let mut event_buf = [MaybeUninit::<u8>::uninit(); 4];
7272

73-
// Ideally we'd write this, but it gets:
73+
// It's tempting to write this, but it gets:
7474
// "captured variable cannot escape `FnMut` closure body".
7575
/*
7676
rustix::io::retry_on_intr(|| b(&mut event_buf)).unwrap();

examples/stdio.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,8 @@ fn key(b: u8) -> String {
348348
format!("^{}", (b + 0x40) as char)
349349
} else if b == 0x7f {
350350
"^?".to_string()
351+
} else if b >= 0x80 {
352+
format!("M-{}", key(b - 0x80))
351353
} else {
352354
format!("{}", b as char)
353355
}

src/backend/libc/event/syscalls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ pub(crate) unsafe fn port_getn(
421421
};
422422

423423
// `port_getn` special-cases a max value of 0 to be a query that returns
424-
// the number of events, so so bail out early if needed.
424+
// the number of events, so bail out early if needed.
425425
if events.1 == 0 {
426426
return Ok(0);
427427
}

src/backend/libc/mount/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,8 @@ bitflags! {
312312
/// Mount and unmount events propagate from the upstream peer group
313313
/// into the downstream.
314314
///
315-
/// In Linux documentation, this flag is named <code>MS_SLAVE</code>,
316-
/// and the concepts of “upstream” and “downstream” are called
315+
/// In Linux documentation, this flag is named `MS_SLAVE`, and the
316+
/// concepts of “upstream” and “downstream” are called
317317
/// “master” and “slave”.
318318
#[doc(alias = "SLAVE")]
319319
const DOWNSTREAM = c::MS_SLAVE;

src/backend/libc/net/netdevice.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
use crate::alloc::string::String;
77
use crate::backend::c;
88
use crate::backend::io::syscalls::ioctl;
9-
use crate::fd::AsFd;
9+
use crate::fd::BorrowedFd;
1010
use crate::io;
1111
#[cfg(feature = "alloc")]
1212
use c::SIOCGIFNAME;
1313
use c::{__c_anonymous_ifr_ifru, c_char, ifreq, IFNAMSIZ, SIOCGIFINDEX};
1414

15-
pub(crate) fn name_to_index(fd: impl AsFd, if_name: &str) -> io::Result<u32> {
15+
pub(crate) fn name_to_index(fd: BorrowedFd<'_>, if_name: &str) -> io::Result<u32> {
1616
let if_name_bytes = if_name.as_bytes();
1717
if if_name_bytes.len() >= IFNAMSIZ as usize {
1818
return Err(io::Errno::NODEV);
@@ -26,21 +26,21 @@ pub(crate) fn name_to_index(fd: impl AsFd, if_name: &str) -> io::Result<u32> {
2626
let mut if_name_c_char_iter = if_name_bytes.iter().map(|byte| *byte as c_char);
2727
ifreq.ifr_name[..if_name_bytes.len()].fill_with(|| if_name_c_char_iter.next().unwrap());
2828

29-
unsafe { ioctl(fd.as_fd(), SIOCGIFINDEX as _, &mut ifreq as *mut ifreq as _) }?;
29+
unsafe { ioctl(fd, SIOCGIFINDEX as _, &mut ifreq as *mut ifreq as _) }?;
3030
let index = unsafe { ifreq.ifr_ifru.ifru_ifindex };
3131
Ok(index as u32)
3232
}
3333

3434
#[cfg(feature = "alloc")]
35-
pub(crate) fn index_to_name(fd: impl AsFd, index: u32) -> io::Result<String> {
35+
pub(crate) fn index_to_name(fd: BorrowedFd<'_>, index: u32) -> io::Result<String> {
3636
let mut ifreq = ifreq {
3737
ifr_name: [0; 16],
3838
ifr_ifru: __c_anonymous_ifr_ifru {
3939
ifru_ifindex: index as _,
4040
},
4141
};
4242

43-
unsafe { ioctl(fd.as_fd(), SIOCGIFNAME as _, &mut ifreq as *mut ifreq as _) }?;
43+
unsafe { ioctl(fd, SIOCGIFNAME as _, &mut ifreq as *mut ifreq as _) }?;
4444

4545
if let Some(nul_byte) = ifreq.ifr_name.iter().position(|char| *char == 0) {
4646
let name: String = ifreq.ifr_name[..nul_byte]

src/backend/linux_raw/mount/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,8 @@ bitflags! {
304304
/// Mount and unmount events propagate from the upstream peer group
305305
/// into the downstream.
306306
///
307-
/// In Linux documentation, this flag is named <code>MS_SLAVE</code>,
308-
/// and the concepts of “upstream” and “downstream” are called
307+
/// In Linux documentation, this flag is named `MS_SLAVE`, and the
308+
/// concepts of “upstream” and “downstream” are called
309309
/// “master” and “slave”.
310310
#[doc(alias = "SLAVE")]
311311
const DOWNSTREAM = linux_raw_sys::general::MS_SLAVE;

src/backend/linux_raw/net/netdevice.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![allow(unsafe_code)]
44

55
use crate::backend::io::syscalls::ioctl;
6-
use crate::fd::AsFd;
6+
use crate::fd::BorrowedFd;
77
use crate::io;
88
use core::ptr::addr_of_mut;
99
use core::{slice, str};
@@ -15,7 +15,7 @@ use linux_raw_sys::net::{ifreq, ifreq__bindgen_ty_1, ifreq__bindgen_ty_2, IFNAMS
1515
#[cfg(feature = "alloc")]
1616
use {alloc::borrow::ToOwned, alloc::string::String};
1717

18-
pub(crate) fn name_to_index(fd: impl AsFd, if_name: &str) -> io::Result<u32> {
18+
pub(crate) fn name_to_index(fd: BorrowedFd<'_>, if_name: &str) -> io::Result<u32> {
1919
let if_name_bytes = if_name.as_bytes();
2020
if if_name_bytes.len() >= IFNAMSIZ as usize {
2121
return Err(io::Errno::NODEV);
@@ -35,21 +35,21 @@ pub(crate) fn name_to_index(fd: impl AsFd, if_name: &str) -> io::Result<u32> {
3535
};
3636
unsafe { ifreq.ifr_ifrn.ifrn_name[..if_name_bytes.len()].copy_from_slice(if_name_bytes) };
3737

38-
unsafe { ioctl(fd.as_fd(), SIOCGIFINDEX, addr_of_mut!(ifreq).cast()) }?;
38+
unsafe { ioctl(fd, SIOCGIFINDEX, addr_of_mut!(ifreq).cast()) }?;
3939
let index = unsafe { ifreq.ifr_ifru.ifru_ivalue };
4040
Ok(index as u32)
4141
}
4242

4343
#[cfg(feature = "alloc")]
44-
pub(crate) fn index_to_name(fd: impl AsFd, index: u32) -> io::Result<String> {
44+
pub(crate) fn index_to_name(fd: BorrowedFd<'_>, index: u32) -> io::Result<String> {
4545
let mut ifreq = ifreq {
4646
ifr_ifrn: ifreq__bindgen_ty_1 { ifrn_name: [0; 16] },
4747
ifr_ifru: ifreq__bindgen_ty_2 {
4848
ifru_ivalue: index as _,
4949
},
5050
};
5151

52-
unsafe { ioctl(fd.as_fd(), SIOCGIFNAME, addr_of_mut!(ifreq).cast()) }?;
52+
unsafe { ioctl(fd, SIOCGIFNAME, addr_of_mut!(ifreq).cast()) }?;
5353

5454
if let Some(nul_byte) = unsafe { ifreq.ifr_ifrn.ifrn_name }
5555
.iter()

src/backend/linux_raw/param/auxv.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -487,10 +487,7 @@ unsafe fn check_elf_base(base: *const Elf_Ehdr) -> Option<NonNull<Elf_Ehdr>> {
487487
return None;
488488
}
489489

490-
let hdr = match check_raw_pointer::<Elf_Ehdr>(base as *mut _) {
491-
Some(hdr) => hdr,
492-
None => return None,
493-
};
490+
let hdr = check_raw_pointer::<Elf_Ehdr>(base as *mut _)?;
494491

495492
let hdr = hdr.as_ref();
496493
if hdr.e_ident[..SELFMAG] != ELFMAG {

src/io/close.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use backend::fd::RawFd;
1010

1111
/// `close(raw_fd)`—Closes a `RawFd` directly.
1212
///
13-
/// Most users won't need to use this, as `OwnedFd` automatically closes its
13+
/// Most users won't need to use this, as [`OwnedFd`] automatically closes its
1414
/// file descriptor on `Drop`.
1515
///
1616
/// This function does not return a `Result`, as it is the [responsibility] of
@@ -33,6 +33,7 @@ use backend::fd::RawFd;
3333
/// - [illumos]
3434
/// - [glibc]
3535
///
36+
/// [`OwnedFd`]: crate::fd::OwnedFd
3637
/// [Beej's Guide to Network Programming]: https://beej.us/guide/bgnet/html/split/system-calls-or-bust.html#close-and-shutdownget-outta-my-face
3738
/// [POSIX]: https://pubs.opengroup.org/onlinepubs/9799919799/functions/close.html
3839
/// [Linux]: https://man7.org/linux/man-pages/man2/close.2.html

src/lib.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,12 @@
8989
//! [`cap-std`]: https://crates.io/crates/cap-std
9090
//! [`system-interface`]: https://crates.io/crates/system-interface
9191
//! [`io-streams`]: https://crates.io/crates/io-streams
92-
//! [`getrandom`]: https://crates.io/crates/getrandom
93-
//! [`bitflags`]: https://crates.io/crates/bitflags
94-
//! [`AsFd`]: https://doc.rust-lang.org/stable/std/os/fd/trait.AsFd.html
95-
//! [`OwnedFd`]: https://doc.rust-lang.org/stable/std/os/fd/struct.OwnedFd.html
92+
//! [`bitflags`]: bitflags
93+
//! [`AsFd`]: crate::fd::AsFd
94+
//! [`OwnedFd`]: crate::fd::OwnedFd
9695
//! [I/O-safe]: https://github.com/rust-lang/rfcs/blob/master/text/3128-io-safety.md
9796
//! [`Arg`]: path::Arg
98-
//! [support for externally defined flags]: https://docs.rs/bitflags/*/bitflags/#externally-defined-flags
97+
//! [support for externally defined flags]: bitflags#externally-defined-flags
9998
10099
#![deny(missing_docs)]
101100
#![allow(stable_features)]

0 commit comments

Comments
 (0)