Skip to content

Commit a5f6668

Browse files
authored
Rollup merge of #82228 - ijackson:nonzero-cint, r=KodrAus
Provide NonZero_c_* integers I'm pretty sure I am going want this for #73125 and it seems like an omission that would be in any case good to remedy. <strike>Because the raw C types are in `std`, not `core`, to achieve this we must export the relevant macros from `core` so that `std` can use them. That's done with a new `num_internals` perma-unstable feature. The macros need to take more parameters for the module to get the types from and feature attributes to use. I have eyeballed the docs output for core, to check that my changes to these macros have made no difference to the core docs output.</strike>
2 parents 3cf201f + 60a9dcc commit a5f6668

File tree

2 files changed

+57
-54
lines changed

2 files changed

+57
-54
lines changed

library/std/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@
263263
#![feature(exact_size_is_empty)]
264264
#![feature(exhaustive_patterns)]
265265
#![feature(extend_one)]
266+
#![feature(extended_key_value_attributes)]
266267
#![feature(external_doc)]
267268
#![feature(fn_traits)]
268269
#![feature(format_args_nl)]

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

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

14-
#[doc(include = "char.md")]
14+
use core::num::*;
15+
16+
macro_rules! type_alias_no_nz {
17+
{
18+
$Docfile:tt, $Alias:ident = $Real:ty;
19+
$( $Cfg:tt )*
20+
} => {
21+
#[doc(include = $Docfile)]
22+
$( $Cfg )*
23+
#[stable(feature = "raw_os", since = "1.1.0")]
24+
pub type $Alias = $Real;
25+
}
26+
}
27+
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;
1549
#[cfg(any(
1650
all(
1751
target_os = "linux",
@@ -52,10 +86,8 @@ mod tests;
5286
)
5387
),
5488
all(target_os = "fuchsia", target_arch = "aarch64")
55-
))]
56-
#[stable(feature = "raw_os", since = "1.1.0")]
57-
pub type c_char = u8;
58-
#[doc(include = "char.md")]
89+
))]}
90+
type_alias! { "char.md", c_char = i8, NonZero_c_char = NonZeroI8;
5991
#[cfg(not(any(
6092
all(
6193
target_os = "linux",
@@ -96,55 +128,25 @@ pub type c_char = u8;
96128
)
97129
),
98130
all(target_os = "fuchsia", target_arch = "aarch64")
99-
)))]
100-
#[stable(feature = "raw_os", since = "1.1.0")]
101-
pub type c_char = i8;
102-
#[doc(include = "schar.md")]
103-
#[stable(feature = "raw_os", since = "1.1.0")]
104-
pub type c_schar = i8;
105-
#[doc(include = "uchar.md")]
106-
#[stable(feature = "raw_os", since = "1.1.0")]
107-
pub type c_uchar = u8;
108-
#[doc(include = "short.md")]
109-
#[stable(feature = "raw_os", since = "1.1.0")]
110-
pub type c_short = i16;
111-
#[doc(include = "ushort.md")]
112-
#[stable(feature = "raw_os", since = "1.1.0")]
113-
pub type c_ushort = u16;
114-
#[doc(include = "int.md")]
115-
#[stable(feature = "raw_os", since = "1.1.0")]
116-
pub type c_int = i32;
117-
#[doc(include = "uint.md")]
118-
#[stable(feature = "raw_os", since = "1.1.0")]
119-
pub type c_uint = u32;
120-
#[doc(include = "long.md")]
121-
#[cfg(any(target_pointer_width = "32", windows))]
122-
#[stable(feature = "raw_os", since = "1.1.0")]
123-
pub type c_long = i32;
124-
#[doc(include = "ulong.md")]
125-
#[cfg(any(target_pointer_width = "32", windows))]
126-
#[stable(feature = "raw_os", since = "1.1.0")]
127-
pub type c_ulong = u32;
128-
#[doc(include = "long.md")]
129-
#[cfg(all(target_pointer_width = "64", not(windows)))]
130-
#[stable(feature = "raw_os", since = "1.1.0")]
131-
pub type c_long = i64;
132-
#[doc(include = "ulong.md")]
133-
#[cfg(all(target_pointer_width = "64", not(windows)))]
134-
#[stable(feature = "raw_os", since = "1.1.0")]
135-
pub type c_ulong = u64;
136-
#[doc(include = "longlong.md")]
137-
#[stable(feature = "raw_os", since = "1.1.0")]
138-
pub type c_longlong = i64;
139-
#[doc(include = "ulonglong.md")]
140-
#[stable(feature = "raw_os", since = "1.1.0")]
141-
pub type c_ulonglong = u64;
142-
#[doc(include = "float.md")]
143-
#[stable(feature = "raw_os", since = "1.1.0")]
144-
pub type c_float = f32;
145-
#[doc(include = "double.md")]
146-
#[stable(feature = "raw_os", since = "1.1.0")]
147-
pub type c_double = f64;
131+
)))]}
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;
139+
#[cfg(any(target_pointer_width = "32", windows))] }
140+
type_alias! { "ulong.md", c_ulong = u32, NonZero_c_ulong = NonZeroU32;
141+
#[cfg(any(target_pointer_width = "32", windows))] }
142+
type_alias! { "long.md", c_long = i64, NonZero_c_long = NonZeroI64;
143+
#[cfg(all(target_pointer_width = "64", not(windows)))] }
144+
type_alias! { "ulong.md", c_ulong = u64, NonZero_c_ulong = NonZeroU64;
145+
#[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; }
148150

149151
#[stable(feature = "raw_os", since = "1.1.0")]
150152
#[doc(no_inline)]

0 commit comments

Comments
 (0)