Skip to content

Commit 4f4ceef

Browse files
Rollup merge of #120295 - reitermarkus:remove-ffi-nonzero, r=dtolnay
Remove `raw_os_nonzero` feature. This feature is superseded by a generic `NonZero` type: #120257 Closes #82363.
2 parents 0a4fd52 + bf4de3a commit 4f4ceef

File tree

7 files changed

+26
-67
lines changed

7 files changed

+26
-67
lines changed

library/core/src/ffi/mod.rs

+14-50
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@
1111

1212
use crate::fmt;
1313
use crate::marker::PhantomData;
14-
use crate::num::*;
1514
use crate::ops::{Deref, DerefMut};
1615

1716
#[stable(feature = "core_c_str", since = "1.64.0")]
1817
pub use self::c_str::{CStr, FromBytesUntilNulError, FromBytesWithNulError};
1918

2019
mod c_str;
2120

22-
macro_rules! type_alias_no_nz {
21+
macro_rules! type_alias {
2322
{
2423
$Docfile:tt, $Alias:ident = $Real:ty;
2524
$( $Cfg:tt )*
@@ -31,49 +30,24 @@ macro_rules! type_alias_no_nz {
3130
}
3231
}
3332

34-
// To verify that the NonZero types in this file's macro invocations correspond
35-
//
36-
// 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'
37-
//
38-
// NB this does not check that the main c_* types are right.
39-
40-
macro_rules! type_alias {
41-
{
42-
$Docfile:tt, $Alias:ident = $Real:ty, $NZAlias:ident = $NZReal:ty;
43-
$( $Cfg:tt )*
44-
} => {
45-
type_alias_no_nz! { $Docfile, $Alias = $Real; $( $Cfg )* }
46-
47-
#[doc = concat!("Type alias for `NonZero` version of [`", stringify!($Alias), "`]")]
48-
#[unstable(feature = "raw_os_nonzero", issue = "82363")]
49-
$( $Cfg )*
50-
pub type $NZAlias = $NZReal;
51-
}
52-
}
53-
54-
type_alias! { "c_char.md", c_char = c_char_definition::c_char, NonZero_c_char = c_char_definition::NonZero_c_char;
55-
#[doc(cfg(all()))] }
33+
type_alias! { "c_char.md", c_char = c_char_definition::c_char; #[doc(cfg(all()))] }
5634

57-
type_alias! { "c_schar.md", c_schar = i8, NonZero_c_schar = NonZeroI8; }
58-
type_alias! { "c_uchar.md", c_uchar = u8, NonZero_c_uchar = NonZeroU8; }
59-
type_alias! { "c_short.md", c_short = i16, NonZero_c_short = NonZeroI16; }
60-
type_alias! { "c_ushort.md", c_ushort = u16, NonZero_c_ushort = NonZeroU16; }
35+
type_alias! { "c_schar.md", c_schar = i8; }
36+
type_alias! { "c_uchar.md", c_uchar = u8; }
37+
type_alias! { "c_short.md", c_short = i16; }
38+
type_alias! { "c_ushort.md", c_ushort = u16; }
6139

62-
type_alias! { "c_int.md", c_int = c_int_definition::c_int, NonZero_c_int = c_int_definition::NonZero_c_int;
63-
#[doc(cfg(all()))] }
64-
type_alias! { "c_uint.md", c_uint = c_int_definition::c_uint, NonZero_c_uint = c_int_definition::NonZero_c_uint;
65-
#[doc(cfg(all()))] }
40+
type_alias! { "c_int.md", c_int = c_int_definition::c_int; #[doc(cfg(all()))] }
41+
type_alias! { "c_uint.md", c_uint = c_int_definition::c_uint; #[doc(cfg(all()))] }
6642

67-
type_alias! { "c_long.md", c_long = c_long_definition::c_long, NonZero_c_long = c_long_definition::NonZero_c_long;
68-
#[doc(cfg(all()))] }
69-
type_alias! { "c_ulong.md", c_ulong = c_long_definition::c_ulong, NonZero_c_ulong = c_long_definition::NonZero_c_ulong;
70-
#[doc(cfg(all()))] }
43+
type_alias! { "c_long.md", c_long = c_long_definition::c_long; #[doc(cfg(all()))] }
44+
type_alias! { "c_ulong.md", c_ulong = c_long_definition::c_ulong; #[doc(cfg(all()))] }
7145

72-
type_alias! { "c_longlong.md", c_longlong = i64, NonZero_c_longlong = NonZeroI64; }
73-
type_alias! { "c_ulonglong.md", c_ulonglong = u64, NonZero_c_ulonglong = NonZeroU64; }
46+
type_alias! { "c_longlong.md", c_longlong = i64; }
47+
type_alias! { "c_ulonglong.md", c_ulonglong = u64; }
7448

75-
type_alias_no_nz! { "c_float.md", c_float = f32; }
76-
type_alias_no_nz! { "c_double.md", c_double = f64; }
49+
type_alias! { "c_float.md", c_float = f32; }
50+
type_alias! { "c_double.md", c_double = f64; }
7751

7852
/// Equivalent to C's `size_t` type, from `stddef.h` (or `cstddef` for C++).
7953
///
@@ -152,11 +126,9 @@ mod c_char_definition {
152126
target_os = "horizon"
153127
))] {
154128
pub type c_char = u8;
155-
pub type NonZero_c_char = crate::num::NonZeroU8;
156129
} else {
157130
// On every other target, c_char is signed.
158131
pub type c_char = i8;
159-
pub type NonZero_c_char = crate::num::NonZeroI8;
160132
}
161133
}
162134
}
@@ -165,14 +137,10 @@ mod c_int_definition {
165137
cfg_if! {
166138
if #[cfg(any(target_arch = "avr", target_arch = "msp430"))] {
167139
pub type c_int = i16;
168-
pub type NonZero_c_int = crate::num::NonZeroI16;
169140
pub type c_uint = u16;
170-
pub type NonZero_c_uint = crate::num::NonZeroU16;
171141
} else {
172142
pub type c_int = i32;
173-
pub type NonZero_c_int = crate::num::NonZeroI32;
174143
pub type c_uint = u32;
175-
pub type NonZero_c_uint = crate::num::NonZeroU32;
176144
}
177145
}
178146
}
@@ -181,15 +149,11 @@ mod c_long_definition {
181149
cfg_if! {
182150
if #[cfg(all(target_pointer_width = "64", not(windows)))] {
183151
pub type c_long = i64;
184-
pub type NonZero_c_long = crate::num::NonZeroI64;
185152
pub type c_ulong = u64;
186-
pub type NonZero_c_ulong = crate::num::NonZeroU64;
187153
} else {
188154
// The minimal size of `long` in the C standard is 32 bits
189155
pub type c_long = i32;
190-
pub type NonZero_c_long = crate::num::NonZeroI32;
191156
pub type c_ulong = u32;
192-
pub type NonZero_c_ulong = crate::num::NonZeroU32;
193157
}
194158
}
195159
}

library/std/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,6 @@
338338
#![feature(portable_simd)]
339339
#![feature(prelude_2024)]
340340
#![feature(ptr_as_uninit)]
341-
#![feature(raw_os_nonzero)]
342341
#![feature(slice_internals)]
343342
#![feature(slice_ptr_get)]
344343
#![feature(slice_range)]

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
use crate::fmt;
22
use crate::io::{self, Error, ErrorKind};
33
use crate::mem;
4-
use crate::num::NonZeroI32;
4+
use crate::num::{NonZero, NonZeroI32};
55
use crate::sys;
66
use crate::sys::cvt;
77
use crate::sys::process::process_common::*;
8-
use core::ffi::NonZero_c_int;
98

109
#[cfg(target_os = "linux")]
1110
use crate::os::linux::process::PidFd;
@@ -935,7 +934,7 @@ impl ExitStatus {
935934
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wait.html. If it is not
936935
// true for a platform pretending to be Unix, the tests (our doctests, and also
937936
// process_unix/tests.rs) will spot it. `ExitStatusError::code` assumes this too.
938-
match NonZero_c_int::try_from(self.0) {
937+
match NonZero::try_from(self.0) {
939938
/* was nonzero */ Ok(failure) => Err(ExitStatusError(failure)),
940939
/* was zero, couldn't convert */ Err(_) => Ok(()),
941940
}
@@ -1092,7 +1091,7 @@ impl fmt::Display for ExitStatus {
10921091
}
10931092

10941093
#[derive(PartialEq, Eq, Clone, Copy)]
1095-
pub struct ExitStatusError(NonZero_c_int);
1094+
pub struct ExitStatusError(NonZero<c_int>);
10961095

10971096
impl Into<ExitStatus> for ExitStatusError {
10981097
fn into(self) -> ExitStatus {

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use crate::fmt;
22
use crate::io;
3-
use crate::num::NonZeroI32;
3+
use crate::num::{NonZero, NonZeroI32};
44
use crate::sys::pal::unix::unsupported::*;
55
use crate::sys::process::process_common::*;
6-
use core::ffi::NonZero_c_int;
76

87
use libc::{c_int, pid_t};
98

@@ -59,7 +58,7 @@ mod wait_status;
5958
pub use wait_status::ExitStatus;
6059

6160
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
62-
pub struct ExitStatusError(NonZero_c_int);
61+
pub struct ExitStatusError(NonZero<c_int>);
6362

6463
impl Into<ExitStatus> for ExitStatusError {
6564
fn into(self) -> ExitStatus {

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
//! Emulated wait status for non-Unix #[cfg(unix) platforms
22
//!
33
//! Separate module to facilitate testing against a real Unix implementation.
4-
use core::ffi::NonZero_c_int;
5-
64
use crate::ffi::c_int;
75
use crate::fmt;
6+
use crate::num::NonZero;
87

98
use super::ExitStatusError;
109

@@ -50,7 +49,7 @@ impl ExitStatus {
5049
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wait.html. If it is not
5150
// true for a platform pretending to be Unix, the tests (our doctests, and also
5251
// process_unix/tests.rs) will spot it. `ExitStatusError::code` assumes this too.
53-
match NonZero_c_int::try_from(self.wait_status) {
52+
match NonZero::try_from(self.wait_status) {
5453
/* was nonzero */ Ok(failure) => Err(ExitStatusError(failure)),
5554
/* was zero, couldn't convert */ Err(_) => Ok(()),
5655
}

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
use crate::fmt;
22
use crate::io::{self, Error, ErrorKind};
3-
use crate::num::NonZeroI32;
3+
use crate::num::{NonZero, NonZeroI32};
44
use crate::sys;
55
use crate::sys::cvt;
66
use crate::sys::process::process_common::*;
77
use crate::sys_common::thread;
8-
use core::ffi::NonZero_c_int;
98
use libc::RTP_ID;
109
use libc::{self, c_char, c_int};
1110

@@ -197,7 +196,7 @@ impl ExitStatus {
197196
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wait.html. If it is not
198197
// true for a platform pretending to be Unix, the tests (our doctests, and also
199198
// process_unix/tests.rs) will spot it. `ExitStatusError::code` assumes this too.
200-
match NonZero_c_int::try_from(self.0) {
199+
match NonZero::try_from(self.0) {
201200
Ok(failure) => Err(ExitStatusError(failure)),
202201
Err(_) => Ok(()),
203202
}
@@ -249,7 +248,7 @@ impl fmt::Display for ExitStatus {
249248
}
250249

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

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

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77

88
use crate::ffi::CStr;
99
use crate::mem;
10+
use crate::num::NonZero;
1011
pub use crate::os::raw::c_int;
1112
use crate::os::raw::{c_char, c_long, c_longlong, c_uint, c_ulong, c_ushort, c_void};
1213
use crate::os::windows::io::{AsRawHandle, BorrowedHandle};
1314
use crate::ptr;
14-
use core::ffi::NonZero_c_ulong;
1515

1616
mod windows_sys;
1717
pub use windows_sys::*;
1818

1919
pub type DWORD = c_ulong;
20-
pub type NonZeroDWORD = NonZero_c_ulong;
20+
pub type NonZeroDWORD = NonZero<c_ulong>;
2121
pub type LARGE_INTEGER = c_longlong;
2222
#[cfg_attr(target_vendor = "uwp", allow(unused))]
2323
pub type LONG = c_long;

0 commit comments

Comments
 (0)