Skip to content

Commit

Permalink
Miscellaneous fixes for the rustc-dep-of-std build. (#820)
Browse files Browse the repository at this point in the history
- Fix `-D elided-lifetimes-in-paths` diagnostics
 - Fix incorrect target_arch name "power"
 - Add a `try_clone_to_owned` function to the no_std polyfill's `BorrowedFd`.
  • Loading branch information
sunfishcode authored Sep 10, 2023
1 parent ba51780 commit 8073ab2
Show file tree
Hide file tree
Showing 26 changed files with 150 additions and 126 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:

env:
# -D warnings is commented out in our install-rust action; re-add it here.
RUSTFLAGS: -D warnings --cfg criterion
RUSTFLAGS: -D warnings -D elided-lifetimes-in-paths --cfg criterion
steps:
- uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -131,7 +131,7 @@ jobs:

env:
# -D warnings is commented out in our install-rust action; re-add it here.
RUSTFLAGS: -D warnings
RUSTFLAGS: -D warnings -D elided-lifetimes-in-paths
steps:
- uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -538,7 +538,7 @@ jobs:
qemu_target: arm-linux-user
env:
# -D warnings is commented out in our install-rust action; re-add it here.
RUSTFLAGS: -D warnings
RUSTFLAGS: -D warnings -D elided-lifetimes-in-paths
QEMU_BUILD_VERSION: 8.0.2
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -625,7 +625,7 @@ jobs:
qemu_target: ppc64le-linux-user
env:
# -D warnings is commented out in our install-rust action; re-add it here.
RUSTFLAGS: --cfg rustix_use_experimental_asm -D warnings
RUSTFLAGS: --cfg rustix_use_experimental_asm -D warnings -D elided-lifetimes-in-paths
RUSTDOCFLAGS: --cfg rustix_use_experimental_asm
CARGO_TARGET_POWERPC64LE_UNKNOWN_LINUX_GNU_RUSTFLAGS: --cfg rustix_use_experimental_asm
QEMU_BUILD_VERSION: 8.0.2
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ rustc-dep-of-std = [
"dep:compiler_builtins",
"linux-raw-sys/rustc-dep-of-std",
"bitflags/rustc-dep-of-std",
"compiler_builtins?/rustc-dep-of-std",
]

# Obsolete and deprecated.
Expand Down
8 changes: 7 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ fn main() {
// enable the libc backend even if rustix is depended on transitively.
let cfg_use_libc = var("CARGO_CFG_RUSTIX_USE_LIBC").is_ok();

// Check for `--features=rustc-dep-of-std`.
let rustc_dep_of_std = var("CARGO_FEATURE_RUSTC_DEP_OF_STD").is_ok();

// Check for eg. `RUSTFLAGS=--cfg=rustix_use_experimental_features`. This
// is a rustc flag rather than a cargo feature flag because it's
// experimental and not something we want accidentally enabled via
Expand All @@ -52,7 +55,10 @@ fn main() {

// If experimental features are enabled, auto-detect and use available
// features.
if rustix_use_experimental_features {
if rustc_dep_of_std {
use_feature("rustc_attrs");
use_feature("core_intrinsics");
} else if rustix_use_experimental_features {
use_feature_or_nothing("rustc_attrs");
use_feature_or_nothing("core_intrinsics");
}
Expand Down
4 changes: 2 additions & 2 deletions src/backend/libc/fs/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2040,12 +2040,12 @@ pub(crate) fn fcntl_fullfsync(fd: BorrowedFd<'_>) -> io::Result<()> {
}

#[cfg(apple)]
pub(crate) fn fcntl_nocache(fd: BorrowedFd, value: bool) -> io::Result<()> {
pub(crate) fn fcntl_nocache(fd: BorrowedFd<'_>, value: bool) -> io::Result<()> {
unsafe { ret(c::fcntl(borrowed_fd(fd), c::F_NOCACHE, value as c::c_int)) }
}

#[cfg(apple)]
pub(crate) fn fcntl_global_nocache(fd: BorrowedFd, value: bool) -> io::Result<()> {
pub(crate) fn fcntl_global_nocache(fd: BorrowedFd<'_>, value: bool) -> io::Result<()> {
unsafe {
ret(c::fcntl(
borrowed_fd(fd),
Expand Down
12 changes: 6 additions & 6 deletions src/backend/libc/io/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub(crate) fn pwrite(fd: BorrowedFd<'_>, buf: &[u8], offset: u64) -> io::Result<
}

#[cfg(not(target_os = "espidf"))]
pub(crate) fn readv(fd: BorrowedFd<'_>, bufs: &mut [IoSliceMut]) -> io::Result<usize> {
pub(crate) fn readv(fd: BorrowedFd<'_>, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
unsafe {
ret_usize(c::readv(
borrowed_fd(fd),
Expand All @@ -90,7 +90,7 @@ pub(crate) fn readv(fd: BorrowedFd<'_>, bufs: &mut [IoSliceMut]) -> io::Result<u
}

#[cfg(not(target_os = "espidf"))]
pub(crate) fn writev(fd: BorrowedFd<'_>, bufs: &[IoSlice]) -> io::Result<usize> {
pub(crate) fn writev(fd: BorrowedFd<'_>, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
unsafe {
ret_usize(c::writev(
borrowed_fd(fd),
Expand All @@ -109,7 +109,7 @@ pub(crate) fn writev(fd: BorrowedFd<'_>, bufs: &[IoSlice]) -> io::Result<usize>
)))]
pub(crate) fn preadv(
fd: BorrowedFd<'_>,
bufs: &mut [IoSliceMut],
bufs: &mut [IoSliceMut<'_>],
offset: u64,
) -> io::Result<usize> {
// Silently cast; we'll get `EINVAL` if the value is negative.
Expand All @@ -131,7 +131,7 @@ pub(crate) fn preadv(
target_os = "redox",
target_os = "solaris"
)))]
pub(crate) fn pwritev(fd: BorrowedFd<'_>, bufs: &[IoSlice], offset: u64) -> io::Result<usize> {
pub(crate) fn pwritev(fd: BorrowedFd<'_>, bufs: &[IoSlice<'_>], offset: u64) -> io::Result<usize> {
// Silently cast; we'll get `EINVAL` if the value is negative.
let offset = offset as i64;
unsafe {
Expand All @@ -147,7 +147,7 @@ pub(crate) fn pwritev(fd: BorrowedFd<'_>, bufs: &[IoSlice], offset: u64) -> io::
#[cfg(linux_kernel)]
pub(crate) fn preadv2(
fd: BorrowedFd<'_>,
bufs: &mut [IoSliceMut],
bufs: &mut [IoSliceMut<'_>],
offset: u64,
flags: ReadWriteFlags,
) -> io::Result<usize> {
Expand All @@ -167,7 +167,7 @@ pub(crate) fn preadv2(
#[cfg(linux_kernel)]
pub(crate) fn pwritev2(
fd: BorrowedFd<'_>,
bufs: &[IoSlice],
bufs: &[IoSlice<'_>],
offset: u64,
flags: ReadWriteFlags,
) -> io::Result<usize> {
Expand Down
12 changes: 6 additions & 6 deletions src/backend/libc/pipe/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ pub(crate) fn pipe_with(flags: PipeFlags) -> io::Result<(OwnedFd, OwnedFd)> {
#[cfg(linux_kernel)]
#[inline]
pub fn splice(
fd_in: BorrowedFd,
fd_in: BorrowedFd<'_>,
off_in: Option<&mut u64>,
fd_out: BorrowedFd,
fd_out: BorrowedFd<'_>,
off_out: Option<&mut u64>,
len: usize,
flags: SpliceFlags,
Expand All @@ -80,8 +80,8 @@ pub fn splice(
#[cfg(linux_kernel)]
#[inline]
pub unsafe fn vmsplice(
fd: BorrowedFd,
bufs: &[IoSliceRaw],
fd: BorrowedFd<'_>,
bufs: &[IoSliceRaw<'_>],
flags: SpliceFlags,
) -> io::Result<usize> {
ret_usize(c::vmsplice(
Expand All @@ -95,8 +95,8 @@ pub unsafe fn vmsplice(
#[cfg(linux_kernel)]
#[inline]
pub fn tee(
fd_in: BorrowedFd,
fd_out: BorrowedFd,
fd_in: BorrowedFd<'_>,
fd_out: BorrowedFd<'_>,
len: usize,
flags: SpliceFlags,
) -> io::Result<usize> {
Expand Down
6 changes: 3 additions & 3 deletions src/backend/libc/pty/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub(crate) fn openpt(flags: OpenptFlags) -> io::Result<OwnedFd> {
any(apple, linux_like, target_os = "freebsd", target_os = "fuchsia")
))]
#[inline]
pub(crate) fn ptsname(fd: BorrowedFd, mut buffer: Vec<u8>) -> io::Result<CString> {
pub(crate) fn ptsname(fd: BorrowedFd<'_>, mut buffer: Vec<u8>) -> io::Result<CString> {
// This code would benefit from having a better way to read into
// uninitialized memory, but that requires `unsafe`.
buffer.clear();
Expand Down Expand Up @@ -93,12 +93,12 @@ pub(crate) fn ptsname(fd: BorrowedFd, mut buffer: Vec<u8>) -> io::Result<CString
}

#[inline]
pub(crate) fn unlockpt(fd: BorrowedFd) -> io::Result<()> {
pub(crate) fn unlockpt(fd: BorrowedFd<'_>) -> io::Result<()> {
unsafe { ret(c::unlockpt(borrowed_fd(fd))) }
}

#[cfg(not(linux_kernel))]
#[inline]
pub(crate) fn grantpt(fd: BorrowedFd) -> io::Result<()> {
pub(crate) fn grantpt(fd: BorrowedFd<'_>) -> io::Result<()> {
unsafe { ret(c::grantpt(borrowed_fd(fd))) }
}
16 changes: 8 additions & 8 deletions src/backend/libc/termios/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub(crate) fn tcsetpgrp(fd: BorrowedFd<'_>, pid: Pid) -> io::Result<()> {

#[cfg(not(any(target_os = "espidf", target_os = "wasi")))]
pub(crate) fn tcsetattr(
fd: BorrowedFd,
fd: BorrowedFd<'_>,
optional_actions: OptionalActions,
termios: &Termios,
) -> io::Result<()> {
Expand Down Expand Up @@ -165,40 +165,40 @@ pub(crate) fn tcsetattr(
}

#[cfg(not(target_os = "wasi"))]
pub(crate) fn tcsendbreak(fd: BorrowedFd) -> io::Result<()> {
pub(crate) fn tcsendbreak(fd: BorrowedFd<'_>) -> io::Result<()> {
unsafe { ret(c::tcsendbreak(borrowed_fd(fd), 0)) }
}

#[cfg(not(any(target_os = "espidf", target_os = "wasi")))]
pub(crate) fn tcdrain(fd: BorrowedFd) -> io::Result<()> {
pub(crate) fn tcdrain(fd: BorrowedFd<'_>) -> io::Result<()> {
unsafe { ret(c::tcdrain(borrowed_fd(fd))) }
}

#[cfg(not(any(target_os = "espidf", target_os = "wasi")))]
pub(crate) fn tcflush(fd: BorrowedFd, queue_selector: QueueSelector) -> io::Result<()> {
pub(crate) fn tcflush(fd: BorrowedFd<'_>, queue_selector: QueueSelector) -> io::Result<()> {
unsafe { ret(c::tcflush(borrowed_fd(fd), queue_selector as _)) }
}

#[cfg(not(any(target_os = "espidf", target_os = "wasi")))]
pub(crate) fn tcflow(fd: BorrowedFd, action: Action) -> io::Result<()> {
pub(crate) fn tcflow(fd: BorrowedFd<'_>, action: Action) -> io::Result<()> {
unsafe { ret(c::tcflow(borrowed_fd(fd), action as _)) }
}

#[cfg(not(target_os = "wasi"))]
pub(crate) fn tcgetsid(fd: BorrowedFd) -> io::Result<Pid> {
pub(crate) fn tcgetsid(fd: BorrowedFd<'_>) -> io::Result<Pid> {
unsafe {
let pid = ret_pid_t(c::tcgetsid(borrowed_fd(fd)))?;
Ok(Pid::from_raw_unchecked(pid))
}
}

#[cfg(not(any(target_os = "espidf", target_os = "wasi")))]
pub(crate) fn tcsetwinsize(fd: BorrowedFd, winsize: Winsize) -> io::Result<()> {
pub(crate) fn tcsetwinsize(fd: BorrowedFd<'_>, winsize: Winsize) -> io::Result<()> {
unsafe { ret(c::ioctl(borrowed_fd(fd), c::TIOCSWINSZ, &winsize)) }
}

#[cfg(not(any(target_os = "espidf", target_os = "wasi")))]
pub(crate) fn tcgetwinsize(fd: BorrowedFd) -> io::Result<Winsize> {
pub(crate) fn tcgetwinsize(fd: BorrowedFd<'_>) -> io::Result<Winsize> {
unsafe {
let mut buf = MaybeUninit::<Winsize>::uninit();
ret(c::ioctl(
Expand Down
2 changes: 1 addition & 1 deletion src/backend/libc/thread/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ pub(crate) fn gettid() -> Pid {

#[cfg(linux_kernel)]
#[inline]
pub(crate) fn setns(fd: BorrowedFd, nstype: c::c_int) -> io::Result<c::c_int> {
pub(crate) fn setns(fd: BorrowedFd<'_>, nstype: c::c_int) -> io::Result<c::c_int> {
// `setns` wasn't supported in glibc until 2.14, and musl until 0.9.5,
// so use `syscall`.
weak_or_syscall! {
Expand Down
2 changes: 1 addition & 1 deletion src/backend/linux_raw/arch/powerpc64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::backend::reg::{
use core::arch::asm;

#[inline]
pub(in crate::backend) unsafe fn syscall0_readonly(nr: SyscallNumber) -> RetReg<R0> {
pub(in crate::backend) unsafe fn syscall0_readonly(nr: SyscallNumber<'_>) -> RetReg<R0> {
let r0;
asm!(
"sc",
Expand Down
16 changes: 8 additions & 8 deletions src/backend/linux_raw/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,45 +186,45 @@ pub(super) fn no_fd<'a, Num: ArgNumber>() -> ArgReg<'a, Num> {
}

#[inline]
pub(super) fn slice_just_addr<T: Sized, Num: ArgNumber>(v: &[T]) -> ArgReg<Num> {
pub(super) fn slice_just_addr<T: Sized, Num: ArgNumber>(v: &[T]) -> ArgReg<'_, Num> {
let mut_ptr = v.as_ptr() as *mut T;
raw_arg(mut_ptr.cast())
}

#[inline]
pub(super) fn slice_just_addr_mut<T: Sized, Num: ArgNumber>(v: &mut [T]) -> ArgReg<Num> {
pub(super) fn slice_just_addr_mut<T: Sized, Num: ArgNumber>(v: &mut [T]) -> ArgReg<'_, Num> {
raw_arg(v.as_mut_ptr().cast())
}

#[inline]
pub(super) fn slice<T: Sized, Num0: ArgNumber, Num1: ArgNumber>(
v: &[T],
) -> (ArgReg<Num0>, ArgReg<Num1>) {
) -> (ArgReg<'_, Num0>, ArgReg<'_, Num1>) {
(slice_just_addr(v), pass_usize(v.len()))
}

#[inline]
pub(super) fn slice_mut<T: Sized, Num0: ArgNumber, Num1: ArgNumber>(
v: &mut [T],
) -> (ArgReg<Num0>, ArgReg<Num1>) {
) -> (ArgReg<'_, Num0>, ArgReg<'_, Num1>) {
(raw_arg(v.as_mut_ptr().cast()), pass_usize(v.len()))
}

#[inline]
pub(super) fn by_ref<T: Sized, Num: ArgNumber>(t: &T) -> ArgReg<Num> {
pub(super) fn by_ref<T: Sized, Num: ArgNumber>(t: &T) -> ArgReg<'_, Num> {
let mut_ptr = as_ptr(t) as *mut T;
raw_arg(mut_ptr.cast())
}

#[inline]
pub(super) fn by_mut<T: Sized, Num: ArgNumber>(t: &mut T) -> ArgReg<Num> {
pub(super) fn by_mut<T: Sized, Num: ArgNumber>(t: &mut T) -> ArgReg<'_, Num> {
raw_arg(as_mut_ptr(t).cast())
}

/// Convert an optional mutable reference into a `usize` for passing to a
/// syscall.
#[inline]
pub(super) fn opt_mut<T: Sized, Num: ArgNumber>(t: Option<&mut T>) -> ArgReg<Num> {
pub(super) fn opt_mut<T: Sized, Num: ArgNumber>(t: Option<&mut T>) -> ArgReg<'_, Num> {
// This optimizes into the equivalent of `transmute(t)`, and has the
// advantage of not requiring `unsafe`.
match t {
Expand All @@ -237,7 +237,7 @@ pub(super) fn opt_mut<T: Sized, Num: ArgNumber>(t: Option<&mut T>) -> ArgReg<Num
/// syscall.
#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
#[inline]
pub(super) fn opt_ref<T: Sized, Num: ArgNumber>(t: Option<&T>) -> ArgReg<Num> {
pub(super) fn opt_ref<T: Sized, Num: ArgNumber>(t: Option<&T>) -> ArgReg<'_, Num> {
// This optimizes into the equivalent of `transmute(t)`, and has the
// advantage of not requiring `unsafe`.
match t {
Expand Down
35 changes: 5 additions & 30 deletions src/backend/linux_raw/io/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@
use crate::backend::conv::loff_t_from_u64;
#[cfg(all(
target_pointer_width = "32",
any(
target_arch = "arm",
target_arch = "mips",
target_arch = "mips32r6",
target_arch = "power"
),
any(target_arch = "arm", target_arch = "mips", target_arch = "mips32r6"),
))]
use crate::backend::conv::zero;
use crate::backend::conv::{
Expand Down Expand Up @@ -47,12 +42,7 @@ pub(crate) fn pread(fd: BorrowedFd<'_>, buf: &mut [u8], pos: u64) -> io::Result<
// <https://github.com/torvalds/linux/blob/fcadab740480e0e0e9fa9bd272acd409884d431a/arch/arm64/kernel/sys32.c#L75>
#[cfg(all(
target_pointer_width = "32",
any(
target_arch = "arm",
target_arch = "mips",
target_arch = "mips32r6",
target_arch = "power"
),
any(target_arch = "arm", target_arch = "mips", target_arch = "mips32r6"),
))]
unsafe {
ret_usize(syscall!(
Expand All @@ -67,12 +57,7 @@ pub(crate) fn pread(fd: BorrowedFd<'_>, buf: &mut [u8], pos: u64) -> io::Result<
}
#[cfg(all(
target_pointer_width = "32",
not(any(
target_arch = "arm",
target_arch = "mips",
target_arch = "mips32r6",
target_arch = "power"
)),
not(any(target_arch = "arm", target_arch = "mips", target_arch = "mips32r6")),
))]
unsafe {
ret_usize(syscall!(
Expand Down Expand Up @@ -182,12 +167,7 @@ pub(crate) fn pwrite(fd: BorrowedFd<'_>, buf: &[u8], pos: u64) -> io::Result<usi
// <https://github.com/torvalds/linux/blob/fcadab740480e0e0e9fa9bd272acd409884d431a/arch/arm64/kernel/sys32.c#L81-L83>
#[cfg(all(
target_pointer_width = "32",
any(
target_arch = "arm",
target_arch = "mips",
target_arch = "mips32r6",
target_arch = "power"
),
any(target_arch = "arm", target_arch = "mips", target_arch = "mips32r6"),
))]
unsafe {
ret_usize(syscall_readonly!(
Expand All @@ -202,12 +182,7 @@ pub(crate) fn pwrite(fd: BorrowedFd<'_>, buf: &[u8], pos: u64) -> io::Result<usi
}
#[cfg(all(
target_pointer_width = "32",
not(any(
target_arch = "arm",
target_arch = "mips",
target_arch = "mips32r6",
target_arch = "power"
)),
not(any(target_arch = "arm", target_arch = "mips", target_arch = "mips32r6")),
))]
unsafe {
ret_usize(syscall_readonly!(
Expand Down
Loading

0 comments on commit 8073ab2

Please sign in to comment.