diff --git a/library/core/src/ffi/mod.rs b/library/core/src/ffi/mod.rs index 7340ad90da509..44200926a32eb 100644 --- a/library/core/src/ffi/mod.rs +++ b/library/core/src/ffi/mod.rs @@ -11,7 +11,6 @@ use crate::fmt; use crate::marker::PhantomData; -use crate::num::*; use crate::ops::{Deref, DerefMut}; #[stable(feature = "core_c_str", since = "1.64.0")] @@ -19,7 +18,7 @@ pub use self::c_str::{CStr, FromBytesUntilNulError, FromBytesWithNulError}; mod c_str; -macro_rules! type_alias_no_nz { +macro_rules! type_alias { { $Docfile:tt, $Alias:ident = $Real:ty; $( $Cfg:tt )* @@ -31,49 +30,24 @@ macro_rules! type_alias_no_nz { } } -// To verify that the NonZero types in this file's macro invocations correspond -// -// perl -n < library/std/src/os/raw/mod.rs -e 'next unless m/type_alias\!/; die "$_ ?" unless m/, (c_\w+) = (\w+), NonZero_(\w+) = NonZero(\w+)/; die "$_ ?" unless $3 eq $1 and $4 eq ucfirst $2' -// -// NB this does not check that the main c_* types are right. - -macro_rules! type_alias { - { - $Docfile:tt, $Alias:ident = $Real:ty, $NZAlias:ident = $NZReal:ty; - $( $Cfg:tt )* - } => { - type_alias_no_nz! { $Docfile, $Alias = $Real; $( $Cfg )* } - - #[doc = concat!("Type alias for `NonZero` version of [`", stringify!($Alias), "`]")] - #[unstable(feature = "raw_os_nonzero", issue = "82363")] - $( $Cfg )* - pub type $NZAlias = $NZReal; - } -} - -type_alias! { "c_char.md", c_char = c_char_definition::c_char, NonZero_c_char = c_char_definition::NonZero_c_char; -#[doc(cfg(all()))] } +type_alias! { "c_char.md", c_char = c_char_definition::c_char; #[doc(cfg(all()))] } -type_alias! { "c_schar.md", c_schar = i8, NonZero_c_schar = NonZeroI8; } -type_alias! { "c_uchar.md", c_uchar = u8, NonZero_c_uchar = NonZeroU8; } -type_alias! { "c_short.md", c_short = i16, NonZero_c_short = NonZeroI16; } -type_alias! { "c_ushort.md", c_ushort = u16, NonZero_c_ushort = NonZeroU16; } +type_alias! { "c_schar.md", c_schar = i8; } +type_alias! { "c_uchar.md", c_uchar = u8; } +type_alias! { "c_short.md", c_short = i16; } +type_alias! { "c_ushort.md", c_ushort = u16; } -type_alias! { "c_int.md", c_int = c_int_definition::c_int, NonZero_c_int = c_int_definition::NonZero_c_int; -#[doc(cfg(all()))] } -type_alias! { "c_uint.md", c_uint = c_int_definition::c_uint, NonZero_c_uint = c_int_definition::NonZero_c_uint; -#[doc(cfg(all()))] } +type_alias! { "c_int.md", c_int = c_int_definition::c_int; #[doc(cfg(all()))] } +type_alias! { "c_uint.md", c_uint = c_int_definition::c_uint; #[doc(cfg(all()))] } -type_alias! { "c_long.md", c_long = c_long_definition::c_long, NonZero_c_long = c_long_definition::NonZero_c_long; -#[doc(cfg(all()))] } -type_alias! { "c_ulong.md", c_ulong = c_long_definition::c_ulong, NonZero_c_ulong = c_long_definition::NonZero_c_ulong; -#[doc(cfg(all()))] } +type_alias! { "c_long.md", c_long = c_long_definition::c_long; #[doc(cfg(all()))] } +type_alias! { "c_ulong.md", c_ulong = c_long_definition::c_ulong; #[doc(cfg(all()))] } -type_alias! { "c_longlong.md", c_longlong = i64, NonZero_c_longlong = NonZeroI64; } -type_alias! { "c_ulonglong.md", c_ulonglong = u64, NonZero_c_ulonglong = NonZeroU64; } +type_alias! { "c_longlong.md", c_longlong = i64; } +type_alias! { "c_ulonglong.md", c_ulonglong = u64; } -type_alias_no_nz! { "c_float.md", c_float = f32; } -type_alias_no_nz! { "c_double.md", c_double = f64; } +type_alias! { "c_float.md", c_float = f32; } +type_alias! { "c_double.md", c_double = f64; } /// Equivalent to C's `size_t` type, from `stddef.h` (or `cstddef` for C++). /// @@ -152,11 +126,9 @@ mod c_char_definition { target_os = "horizon" ))] { pub type c_char = u8; - pub type NonZero_c_char = crate::num::NonZeroU8; } else { // On every other target, c_char is signed. pub type c_char = i8; - pub type NonZero_c_char = crate::num::NonZeroI8; } } } @@ -165,14 +137,10 @@ mod c_int_definition { cfg_if! { if #[cfg(any(target_arch = "avr", target_arch = "msp430"))] { pub type c_int = i16; - pub type NonZero_c_int = crate::num::NonZeroI16; pub type c_uint = u16; - pub type NonZero_c_uint = crate::num::NonZeroU16; } else { pub type c_int = i32; - pub type NonZero_c_int = crate::num::NonZeroI32; pub type c_uint = u32; - pub type NonZero_c_uint = crate::num::NonZeroU32; } } } @@ -181,15 +149,11 @@ mod c_long_definition { cfg_if! { if #[cfg(all(target_pointer_width = "64", not(windows)))] { pub type c_long = i64; - pub type NonZero_c_long = crate::num::NonZeroI64; pub type c_ulong = u64; - pub type NonZero_c_ulong = crate::num::NonZeroU64; } else { // The minimal size of `long` in the C standard is 32 bits pub type c_long = i32; - pub type NonZero_c_long = crate::num::NonZeroI32; pub type c_ulong = u32; - pub type NonZero_c_ulong = crate::num::NonZeroU32; } } } diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 2e458562744bf..ccc7a1592312d 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -338,7 +338,6 @@ #![feature(portable_simd)] #![feature(prelude_2024)] #![feature(ptr_as_uninit)] -#![feature(raw_os_nonzero)] #![feature(slice_internals)] #![feature(slice_ptr_get)] #![feature(slice_range)] diff --git a/library/std/src/sys/pal/unix/process/process_unix.rs b/library/std/src/sys/pal/unix/process/process_unix.rs index df0fe2bb9d84a..94c4c56bd51cf 100644 --- a/library/std/src/sys/pal/unix/process/process_unix.rs +++ b/library/std/src/sys/pal/unix/process/process_unix.rs @@ -1,11 +1,10 @@ use crate::fmt; use crate::io::{self, Error, ErrorKind}; use crate::mem; -use crate::num::NonZeroI32; +use crate::num::{NonZero, NonZeroI32}; use crate::sys; use crate::sys::cvt; use crate::sys::process::process_common::*; -use core::ffi::NonZero_c_int; #[cfg(target_os = "linux")] use crate::os::linux::process::PidFd; @@ -935,7 +934,7 @@ impl ExitStatus { // https://pubs.opengroup.org/onlinepubs/9699919799/functions/wait.html. If it is not // true for a platform pretending to be Unix, the tests (our doctests, and also // process_unix/tests.rs) will spot it. `ExitStatusError::code` assumes this too. - match NonZero_c_int::try_from(self.0) { + match NonZero::try_from(self.0) { /* was nonzero */ Ok(failure) => Err(ExitStatusError(failure)), /* was zero, couldn't convert */ Err(_) => Ok(()), } @@ -1092,7 +1091,7 @@ impl fmt::Display for ExitStatus { } #[derive(PartialEq, Eq, Clone, Copy)] -pub struct ExitStatusError(NonZero_c_int); +pub struct ExitStatusError(NonZero); impl Into for ExitStatusError { fn into(self) -> ExitStatus { diff --git a/library/std/src/sys/pal/unix/process/process_unsupported.rs b/library/std/src/sys/pal/unix/process/process_unsupported.rs index 9453c8a384e24..89a2a0c6e567b 100644 --- a/library/std/src/sys/pal/unix/process/process_unsupported.rs +++ b/library/std/src/sys/pal/unix/process/process_unsupported.rs @@ -1,9 +1,8 @@ use crate::fmt; use crate::io; -use crate::num::NonZeroI32; +use crate::num::{NonZero, NonZeroI32}; use crate::sys::pal::unix::unsupported::*; use crate::sys::process::process_common::*; -use core::ffi::NonZero_c_int; use libc::{c_int, pid_t}; @@ -59,7 +58,7 @@ mod wait_status; pub use wait_status::ExitStatus; #[derive(PartialEq, Eq, Clone, Copy, Debug)] -pub struct ExitStatusError(NonZero_c_int); +pub struct ExitStatusError(NonZero); impl Into for ExitStatusError { fn into(self) -> ExitStatus { diff --git a/library/std/src/sys/pal/unix/process/process_unsupported/wait_status.rs b/library/std/src/sys/pal/unix/process/process_unsupported/wait_status.rs index 72b7ae18cff27..e6dfadcf4a4cf 100644 --- a/library/std/src/sys/pal/unix/process/process_unsupported/wait_status.rs +++ b/library/std/src/sys/pal/unix/process/process_unsupported/wait_status.rs @@ -1,10 +1,9 @@ //! Emulated wait status for non-Unix #[cfg(unix) platforms //! //! Separate module to facilitate testing against a real Unix implementation. -use core::ffi::NonZero_c_int; - use crate::ffi::c_int; use crate::fmt; +use crate::num::NonZero; use super::ExitStatusError; @@ -50,7 +49,7 @@ impl ExitStatus { // https://pubs.opengroup.org/onlinepubs/9699919799/functions/wait.html. If it is not // true for a platform pretending to be Unix, the tests (our doctests, and also // process_unix/tests.rs) will spot it. `ExitStatusError::code` assumes this too. - match NonZero_c_int::try_from(self.wait_status) { + match NonZero::try_from(self.wait_status) { /* was nonzero */ Ok(failure) => Err(ExitStatusError(failure)), /* was zero, couldn't convert */ Err(_) => Ok(()), } diff --git a/library/std/src/sys/pal/unix/process/process_vxworks.rs b/library/std/src/sys/pal/unix/process/process_vxworks.rs index 1ff2b2fb3833f..5b4e94d0f1b97 100644 --- a/library/std/src/sys/pal/unix/process/process_vxworks.rs +++ b/library/std/src/sys/pal/unix/process/process_vxworks.rs @@ -1,11 +1,10 @@ use crate::fmt; use crate::io::{self, Error, ErrorKind}; -use crate::num::NonZeroI32; +use crate::num::{NonZero, NonZeroI32}; use crate::sys; use crate::sys::cvt; use crate::sys::process::process_common::*; use crate::sys_common::thread; -use core::ffi::NonZero_c_int; use libc::RTP_ID; use libc::{self, c_char, c_int}; @@ -197,7 +196,7 @@ impl ExitStatus { // https://pubs.opengroup.org/onlinepubs/9699919799/functions/wait.html. If it is not // true for a platform pretending to be Unix, the tests (our doctests, and also // process_unix/tests.rs) will spot it. `ExitStatusError::code` assumes this too. - match NonZero_c_int::try_from(self.0) { + match NonZero::try_from(self.0) { Ok(failure) => Err(ExitStatusError(failure)), Err(_) => Ok(()), } @@ -249,7 +248,7 @@ impl fmt::Display for ExitStatus { } #[derive(PartialEq, Eq, Clone, Copy, Debug)] -pub struct ExitStatusError(NonZero_c_int); +pub struct ExitStatusError(NonZero); impl Into for ExitStatusError { fn into(self) -> ExitStatus { diff --git a/library/std/src/sys/pal/windows/c.rs b/library/std/src/sys/pal/windows/c.rs index d55d9bace811c..1a59ac9a9cadf 100644 --- a/library/std/src/sys/pal/windows/c.rs +++ b/library/std/src/sys/pal/windows/c.rs @@ -7,17 +7,17 @@ use crate::ffi::CStr; use crate::mem; +use crate::num::NonZero; pub use crate::os::raw::c_int; use crate::os::raw::{c_char, c_long, c_longlong, c_uint, c_ulong, c_ushort, c_void}; use crate::os::windows::io::{AsRawHandle, BorrowedHandle}; use crate::ptr; -use core::ffi::NonZero_c_ulong; mod windows_sys; pub use windows_sys::*; pub type DWORD = c_ulong; -pub type NonZeroDWORD = NonZero_c_ulong; +pub type NonZeroDWORD = NonZero; pub type LARGE_INTEGER = c_longlong; #[cfg_attr(target_vendor = "uwp", allow(unused))] pub type LONG = c_long;