Skip to content

Commit 1f8a450

Browse files
committed
Add a test to ensure that RawFd is the size we assume it is.
1 parent 1c6bf04 commit 1f8a450

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

library/std/src/os/unix/io/fd.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
33
#![unstable(feature = "io_safety", issue = "87074")]
44

5+
// Tests for this module
6+
#[cfg(test)]
7+
mod tests;
8+
59
use super::raw::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
610
use crate::fmt;
711
use crate::fs;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
use crate::mem::size_of;
2+
use crate::os::unix::io::RawFd;
3+
4+
#[test]
5+
fn test_raw_fd_layout() {
6+
// `OwnedFd` and `BorrowedFd` use `rustc_layout_scalar_valid_range_start`
7+
// and `rustc_layout_scalar_valid_range_end`, with values that depend on
8+
// the bit width of `RawFd`. If this ever changes, those values will need
9+
// to be updated.
10+
assert_eq!(size_of::<RawFd>(), 4);
11+
}

library/std/src/os/wasi/io/fd.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
33
#![unstable(feature = "wasi_ext", issue = "71213")]
44

5+
// Tests for this module
6+
#[cfg(test)]
7+
mod tests;
8+
59
use super::raw::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
610
use crate::fmt;
711
use crate::fs;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
use std::mem::size_of;
2+
use std::os::wasi::io::RawFd;
3+
4+
#[test]
5+
fn test_raw_fd_layout() {
6+
/// `OwnedFd` and `BorrowedFd` use `rustc_layout_scalar_valid_range_start`
7+
/// and `rustc_layout_scalar_valid_range_end`, with values that depend on
8+
/// the bit width of `RawFd`. If this ever changes, those values will need
9+
/// to be updated.
10+
assert_eq!(size_of::<RawFd>(), 4);
11+
}

0 commit comments

Comments
 (0)