From 585acd8ef43948d1ca374668c7f109f9bde752e5 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Wed, 15 Sep 2021 13:49:27 -0700 Subject: [PATCH] Delete NonZero_c_abominations --- library/std/src/os/raw/mod.rs | 56 ++++++------------- .../std/src/sys/unix/process/process_unix.rs | 7 +-- .../sys/unix/process/process_unsupported.rs | 5 +- .../src/sys/unix/process/process_vxworks.rs | 7 +-- library/std/src/sys/windows/c.rs | 4 +- 5 files changed, 27 insertions(+), 52 deletions(-) diff --git a/library/std/src/os/raw/mod.rs b/library/std/src/os/raw/mod.rs index 1e220ea30ab95..d9495d88a4022 100644 --- a/library/std/src/os/raw/mod.rs +++ b/library/std/src/os/raw/mod.rs @@ -11,9 +11,7 @@ #[cfg(test)] mod tests; -use core::num::*; - -macro_rules! type_alias_no_nz { +macro_rules! type_alias { { $Docfile:tt, $Alias:ident = $Real:ty; $( $Cfg:tt )* @@ -25,27 +23,7 @@ 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! { "char.md", c_char = u8, NonZero_c_char = NonZeroU8; +type_alias! { "char.md", c_char = u8; #[cfg(any( all( target_os = "linux", @@ -87,7 +65,7 @@ type_alias! { "char.md", c_char = u8, NonZero_c_char = NonZeroU8; ), all(target_os = "fuchsia", target_arch = "aarch64") ))]} -type_alias! { "char.md", c_char = i8, NonZero_c_char = NonZeroI8; +type_alias! { "char.md", c_char = i8; #[cfg(not(any( all( target_os = "linux", @@ -129,24 +107,24 @@ type_alias! { "char.md", c_char = i8, NonZero_c_char = NonZeroI8; ), all(target_os = "fuchsia", target_arch = "aarch64") )))]} -type_alias! { "schar.md", c_schar = i8, NonZero_c_schar = NonZeroI8; } -type_alias! { "uchar.md", c_uchar = u8, NonZero_c_uchar = NonZeroU8; } -type_alias! { "short.md", c_short = i16, NonZero_c_short = NonZeroI16; } -type_alias! { "ushort.md", c_ushort = u16, NonZero_c_ushort = NonZeroU16; } -type_alias! { "int.md", c_int = i32, NonZero_c_int = NonZeroI32; } -type_alias! { "uint.md", c_uint = u32, NonZero_c_uint = NonZeroU32; } -type_alias! { "long.md", c_long = i32, NonZero_c_long = NonZeroI32; +type_alias! { "schar.md", c_schar = i8; } +type_alias! { "uchar.md", c_uchar = u8; } +type_alias! { "short.md", c_short = i16; } +type_alias! { "ushort.md", c_ushort = u16; } +type_alias! { "int.md", c_int = i32; } +type_alias! { "uint.md", c_uint = u32; } +type_alias! { "long.md", c_long = i32; #[cfg(any(target_pointer_width = "32", windows))] } -type_alias! { "ulong.md", c_ulong = u32, NonZero_c_ulong = NonZeroU32; +type_alias! { "ulong.md", c_ulong = u32; #[cfg(any(target_pointer_width = "32", windows))] } -type_alias! { "long.md", c_long = i64, NonZero_c_long = NonZeroI64; +type_alias! { "long.md", c_long = i64; #[cfg(all(target_pointer_width = "64", not(windows)))] } -type_alias! { "ulong.md", c_ulong = u64, NonZero_c_ulong = NonZeroU64; +type_alias! { "ulong.md", c_ulong = u64; #[cfg(all(target_pointer_width = "64", not(windows)))] } -type_alias! { "longlong.md", c_longlong = i64, NonZero_c_longlong = NonZeroI64; } -type_alias! { "ulonglong.md", c_ulonglong = u64, NonZero_c_ulonglong = NonZeroU64; } -type_alias_no_nz! { "float.md", c_float = f32; } -type_alias_no_nz! { "double.md", c_double = f64; } +type_alias! { "longlong.md", c_longlong = i64; } +type_alias! { "ulonglong.md", c_ulonglong = u64; } +type_alias! { "float.md", c_float = f32; } +type_alias! { "double.md", c_double = f64; } #[stable(feature = "raw_os", since = "1.1.0")] #[doc(no_inline)] diff --git a/library/std/src/sys/unix/process/process_unix.rs b/library/std/src/sys/unix/process/process_unix.rs index 12edf04a4e2e9..81ebfd50497c8 100644 --- a/library/std/src/sys/unix/process/process_unix.rs +++ b/library/std/src/sys/unix/process/process_unix.rs @@ -2,8 +2,7 @@ use crate::convert::{TryFrom, TryInto}; use crate::fmt; use crate::io::{self, Error, ErrorKind}; use crate::mem; -use crate::num::NonZeroI32; -use crate::os::raw::NonZero_c_int; +use crate::num::{NonZero, NonZeroI32}; use crate::ptr; use crate::sys; use crate::sys::cvt; @@ -625,7 +624,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 // procsss_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(()), } @@ -684,7 +683,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/unix/process/process_unsupported.rs b/library/std/src/sys/unix/process/process_unsupported.rs index 7d549d060fd88..95b1cbe13fa14 100644 --- a/library/std/src/sys/unix/process/process_unsupported.rs +++ b/library/std/src/sys/unix/process/process_unsupported.rs @@ -2,8 +2,7 @@ use crate::convert::{TryFrom, TryInto}; use crate::fmt; use crate::io; use crate::io::ErrorKind; -use crate::num::NonZeroI32; -use crate::os::raw::NonZero_c_int; +use crate::num::{NonZero, NonZeroI32}; use crate::sys; use crate::sys::cvt; use crate::sys::pipe::AnonPipe; @@ -107,7 +106,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/unix/process/process_vxworks.rs b/library/std/src/sys/unix/process/process_vxworks.rs index c17822f512532..245154026e7ad 100644 --- a/library/std/src/sys/unix/process/process_vxworks.rs +++ b/library/std/src/sys/unix/process/process_vxworks.rs @@ -1,8 +1,7 @@ use crate::convert::{TryFrom, TryInto}; use crate::fmt; use crate::io::{self, Error, ErrorKind}; -use crate::num::NonZeroI32; -use crate::os::raw::NonZero_c_int; +use crate::num::{NonZero, NonZeroI32}; use crate::sys; use crate::sys::cvt; use crate::sys::process::process_common::*; @@ -196,7 +195,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 // procsss_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(()), } @@ -248,7 +247,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/windows/c.rs b/library/std/src/sys/windows/c.rs index 6fb850d182889..a172b1efda7ac 100644 --- a/library/std/src/sys/windows/c.rs +++ b/library/std/src/sys/windows/c.rs @@ -4,7 +4,7 @@ #![cfg_attr(test, allow(dead_code))] #![unstable(issue = "none", feature = "windows_c")] -use crate::os::raw::NonZero_c_ulong; +use crate::num::NonZero; use crate::os::raw::{c_char, c_int, c_long, c_longlong, c_uint, c_ulong, c_ushort}; use crate::ptr; @@ -19,7 +19,7 @@ pub use self::FILE_INFO_BY_HANDLE_CLASS::*; pub type DWORD_PTR = ULONG_PTR; pub type DWORD = c_ulong; -pub type NonZeroDWORD = NonZero_c_ulong; +pub type NonZeroDWORD = NonZero; pub type HANDLE = LPVOID; pub type HINSTANCE = HANDLE; pub type HMODULE = HINSTANCE;