Skip to content

Commit 585acd8

Browse files
committed
Delete NonZero_c_abominations
1 parent f6bedf5 commit 585acd8

File tree

5 files changed

+27
-52
lines changed

5 files changed

+27
-52
lines changed

library/std/src/os/raw/mod.rs

+17-39
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
#[cfg(test)]
1212
mod tests;
1313

14-
use core::num::*;
15-
16-
macro_rules! type_alias_no_nz {
14+
macro_rules! type_alias {
1715
{
1816
$Docfile:tt, $Alias:ident = $Real:ty;
1917
$( $Cfg:tt )*
@@ -25,27 +23,7 @@ macro_rules! type_alias_no_nz {
2523
}
2624
}
2725

28-
// To verify that the NonZero types in this file's macro invocations correspond
29-
//
30-
// 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'
31-
//
32-
// NB this does not check that the main c_* types are right.
33-
34-
macro_rules! type_alias {
35-
{
36-
$Docfile:tt, $Alias:ident = $Real:ty, $NZAlias:ident = $NZReal:ty;
37-
$( $Cfg:tt )*
38-
} => {
39-
type_alias_no_nz! { $Docfile, $Alias = $Real; $( $Cfg )* }
40-
41-
#[doc = concat!("Type alias for `NonZero` version of [`", stringify!($Alias), "`]")]
42-
#[unstable(feature = "raw_os_nonzero", issue = "82363")]
43-
$( $Cfg )*
44-
pub type $NZAlias = $NZReal;
45-
}
46-
}
47-
48-
type_alias! { "char.md", c_char = u8, NonZero_c_char = NonZeroU8;
26+
type_alias! { "char.md", c_char = u8;
4927
#[cfg(any(
5028
all(
5129
target_os = "linux",
@@ -87,7 +65,7 @@ type_alias! { "char.md", c_char = u8, NonZero_c_char = NonZeroU8;
8765
),
8866
all(target_os = "fuchsia", target_arch = "aarch64")
8967
))]}
90-
type_alias! { "char.md", c_char = i8, NonZero_c_char = NonZeroI8;
68+
type_alias! { "char.md", c_char = i8;
9169
#[cfg(not(any(
9270
all(
9371
target_os = "linux",
@@ -129,24 +107,24 @@ type_alias! { "char.md", c_char = i8, NonZero_c_char = NonZeroI8;
129107
),
130108
all(target_os = "fuchsia", target_arch = "aarch64")
131109
)))]}
132-
type_alias! { "schar.md", c_schar = i8, NonZero_c_schar = NonZeroI8; }
133-
type_alias! { "uchar.md", c_uchar = u8, NonZero_c_uchar = NonZeroU8; }
134-
type_alias! { "short.md", c_short = i16, NonZero_c_short = NonZeroI16; }
135-
type_alias! { "ushort.md", c_ushort = u16, NonZero_c_ushort = NonZeroU16; }
136-
type_alias! { "int.md", c_int = i32, NonZero_c_int = NonZeroI32; }
137-
type_alias! { "uint.md", c_uint = u32, NonZero_c_uint = NonZeroU32; }
138-
type_alias! { "long.md", c_long = i32, NonZero_c_long = NonZeroI32;
110+
type_alias! { "schar.md", c_schar = i8; }
111+
type_alias! { "uchar.md", c_uchar = u8; }
112+
type_alias! { "short.md", c_short = i16; }
113+
type_alias! { "ushort.md", c_ushort = u16; }
114+
type_alias! { "int.md", c_int = i32; }
115+
type_alias! { "uint.md", c_uint = u32; }
116+
type_alias! { "long.md", c_long = i32;
139117
#[cfg(any(target_pointer_width = "32", windows))] }
140-
type_alias! { "ulong.md", c_ulong = u32, NonZero_c_ulong = NonZeroU32;
118+
type_alias! { "ulong.md", c_ulong = u32;
141119
#[cfg(any(target_pointer_width = "32", windows))] }
142-
type_alias! { "long.md", c_long = i64, NonZero_c_long = NonZeroI64;
120+
type_alias! { "long.md", c_long = i64;
143121
#[cfg(all(target_pointer_width = "64", not(windows)))] }
144-
type_alias! { "ulong.md", c_ulong = u64, NonZero_c_ulong = NonZeroU64;
122+
type_alias! { "ulong.md", c_ulong = u64;
145123
#[cfg(all(target_pointer_width = "64", not(windows)))] }
146-
type_alias! { "longlong.md", c_longlong = i64, NonZero_c_longlong = NonZeroI64; }
147-
type_alias! { "ulonglong.md", c_ulonglong = u64, NonZero_c_ulonglong = NonZeroU64; }
148-
type_alias_no_nz! { "float.md", c_float = f32; }
149-
type_alias_no_nz! { "double.md", c_double = f64; }
124+
type_alias! { "longlong.md", c_longlong = i64; }
125+
type_alias! { "ulonglong.md", c_ulonglong = u64; }
126+
type_alias! { "float.md", c_float = f32; }
127+
type_alias! { "double.md", c_double = f64; }
150128

151129
#[stable(feature = "raw_os", since = "1.1.0")]
152130
#[doc(no_inline)]

library/std/src/sys/unix/process/process_unix.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ use crate::convert::{TryFrom, TryInto};
22
use crate::fmt;
33
use crate::io::{self, Error, ErrorKind};
44
use crate::mem;
5-
use crate::num::NonZeroI32;
6-
use crate::os::raw::NonZero_c_int;
5+
use crate::num::{NonZero, NonZeroI32};
76
use crate::ptr;
87
use crate::sys;
98
use crate::sys::cvt;
@@ -625,7 +624,7 @@ impl ExitStatus {
625624
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wait.html . If it is not
626625
// true for a platform pretending to be Unix, the tests (our doctests, and also
627626
// procsss_unix/tests.rs) will spot it. `ExitStatusError::code` assumes this too.
628-
match NonZero_c_int::try_from(self.0) {
627+
match NonZero::<c_int>::try_from(self.0) {
629628
/* was nonzero */ Ok(failure) => Err(ExitStatusError(failure)),
630629
/* was zero, couldn't convert */ Err(_) => Ok(()),
631630
}
@@ -684,7 +683,7 @@ impl fmt::Display for ExitStatus {
684683
}
685684

686685
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
687-
pub struct ExitStatusError(NonZero_c_int);
686+
pub struct ExitStatusError(NonZero<c_int>);
688687

689688
impl Into<ExitStatus> for ExitStatusError {
690689
fn into(self) -> ExitStatus {

library/std/src/sys/unix/process/process_unsupported.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ use crate::convert::{TryFrom, TryInto};
22
use crate::fmt;
33
use crate::io;
44
use crate::io::ErrorKind;
5-
use crate::num::NonZeroI32;
6-
use crate::os::raw::NonZero_c_int;
5+
use crate::num::{NonZero, NonZeroI32};
76
use crate::sys;
87
use crate::sys::cvt;
98
use crate::sys::pipe::AnonPipe;
@@ -107,7 +106,7 @@ impl fmt::Display for ExitStatus {
107106
}
108107

109108
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
110-
pub struct ExitStatusError(NonZero_c_int);
109+
pub struct ExitStatusError(NonZero<c_int>);
111110

112111
impl Into<ExitStatus> for ExitStatusError {
113112
fn into(self) -> ExitStatus {

library/std/src/sys/unix/process/process_vxworks.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use crate::convert::{TryFrom, TryInto};
22
use crate::fmt;
33
use crate::io::{self, Error, ErrorKind};
4-
use crate::num::NonZeroI32;
5-
use crate::os::raw::NonZero_c_int;
4+
use crate::num::{NonZero, NonZeroI32};
65
use crate::sys;
76
use crate::sys::cvt;
87
use crate::sys::process::process_common::*;
@@ -196,7 +195,7 @@ impl ExitStatus {
196195
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wait.html . If it is not
197196
// true for a platform pretending to be Unix, the tests (our doctests, and also
198197
// procsss_unix/tests.rs) will spot it. `ExitStatusError::code` assumes this too.
199-
match NonZero_c_int::try_from(self.0) {
198+
match NonZero::<c_int>::try_from(self.0) {
200199
Ok(failure) => Err(ExitStatusError(failure)),
201200
Err(_) => Ok(()),
202201
}
@@ -248,7 +247,7 @@ impl fmt::Display for ExitStatus {
248247
}
249248

250249
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
251-
pub struct ExitStatusError(NonZero_c_int);
250+
pub struct ExitStatusError(NonZero<c_int>);
252251

253252
impl Into<ExitStatus> for ExitStatusError {
254253
fn into(self) -> ExitStatus {

library/std/src/sys/windows/c.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#![cfg_attr(test, allow(dead_code))]
55
#![unstable(issue = "none", feature = "windows_c")]
66

7-
use crate::os::raw::NonZero_c_ulong;
7+
use crate::num::NonZero;
88
use crate::os::raw::{c_char, c_int, c_long, c_longlong, c_uint, c_ulong, c_ushort};
99
use crate::ptr;
1010

@@ -19,7 +19,7 @@ pub use self::FILE_INFO_BY_HANDLE_CLASS::*;
1919

2020
pub type DWORD_PTR = ULONG_PTR;
2121
pub type DWORD = c_ulong;
22-
pub type NonZeroDWORD = NonZero_c_ulong;
22+
pub type NonZeroDWORD = NonZero<DWORD>;
2323
pub type HANDLE = LPVOID;
2424
pub type HINSTANCE = HANDLE;
2525
pub type HMODULE = HINSTANCE;

0 commit comments

Comments
 (0)