about summary refs log tree commit diff
path: root/library/std/src/os
diff options
context:
space:
mode:
authorIan Jackson <ijackson@chiark.greenend.org.uk>2021-02-17 19:51:27 +0000
committerIan Jackson <ijackson@chiark.greenend.org.uk>2021-02-17 20:36:59 +0000
commitd6b9d9a1d6a73cd99b0a1f959d3afa77a44bb8bd (patch)
treef85cfd8f55631f5b4b5ae32f2b028f900bd2750e /library/std/src/os
parentee88f46bb5e27c4d9f30326e69ff2298dcbeecb1 (diff)
downloadrust-d6b9d9a1d6a73cd99b0a1f959d3afa77a44bb8bd.tar.gz
rust-d6b9d9a1d6a73cd99b0a1f959d3afa77a44bb8bd.zip
std::src::os::raw: Refactor, introducing macro type_alias!
This file contained a lot of repetitive code.  This was about to get
considerably worse, with introduction of a slew of new aliases.

No functional change.  I've eyeballed the docs and they don't seem to
have changed either.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Diffstat (limited to 'library/std/src/os')
-rw-r--r--library/std/src/os/raw/mod.rs81
1 files changed, 27 insertions, 54 deletions
diff --git a/library/std/src/os/raw/mod.rs b/library/std/src/os/raw/mod.rs
index 16272aa0571..1a2158555e6 100644
--- a/library/std/src/os/raw/mod.rs
+++ b/library/std/src/os/raw/mod.rs
@@ -11,7 +11,16 @@
 #[cfg(test)]
 mod tests;
 
-#[doc(include = "char.md")]
+macro_rules! type_alias {
+    { $Docfile:tt, $Alias:ident = $Real:ty; $( $Cfg:tt )* } => {
+        #[doc(include = $Docfile)]
+        $( $Cfg )*
+        #[stable(feature = "raw_os", since = "1.1.0")]
+        pub type $Alias = $Real;
+    }
+}
+
+type_alias! { "char.md", c_char = u8;
 #[cfg(any(
     all(
         target_os = "linux",
@@ -52,10 +61,8 @@ mod tests;
         )
     ),
     all(target_os = "fuchsia", target_arch = "aarch64")
-))]
-#[stable(feature = "raw_os", since = "1.1.0")]
-pub type c_char = u8;
-#[doc(include = "char.md")]
+))]}
+type_alias! { "char.md", c_char = i8;
 #[cfg(not(any(
     all(
         target_os = "linux",
@@ -96,55 +103,21 @@ pub type c_char = u8;
         )
     ),
     all(target_os = "fuchsia", target_arch = "aarch64")
-)))]
-#[stable(feature = "raw_os", since = "1.1.0")]
-pub type c_char = i8;
-#[doc(include = "schar.md")]
-#[stable(feature = "raw_os", since = "1.1.0")]
-pub type c_schar = i8;
-#[doc(include = "uchar.md")]
-#[stable(feature = "raw_os", since = "1.1.0")]
-pub type c_uchar = u8;
-#[doc(include = "short.md")]
-#[stable(feature = "raw_os", since = "1.1.0")]
-pub type c_short = i16;
-#[doc(include = "ushort.md")]
-#[stable(feature = "raw_os", since = "1.1.0")]
-pub type c_ushort = u16;
-#[doc(include = "int.md")]
-#[stable(feature = "raw_os", since = "1.1.0")]
-pub type c_int = i32;
-#[doc(include = "uint.md")]
-#[stable(feature = "raw_os", since = "1.1.0")]
-pub type c_uint = u32;
-#[doc(include = "long.md")]
-#[cfg(any(target_pointer_width = "32", windows))]
-#[stable(feature = "raw_os", since = "1.1.0")]
-pub type c_long = i32;
-#[doc(include = "ulong.md")]
-#[cfg(any(target_pointer_width = "32", windows))]
-#[stable(feature = "raw_os", since = "1.1.0")]
-pub type c_ulong = u32;
-#[doc(include = "long.md")]
-#[cfg(all(target_pointer_width = "64", not(windows)))]
-#[stable(feature = "raw_os", since = "1.1.0")]
-pub type c_long = i64;
-#[doc(include = "ulong.md")]
-#[cfg(all(target_pointer_width = "64", not(windows)))]
-#[stable(feature = "raw_os", since = "1.1.0")]
-pub type c_ulong = u64;
-#[doc(include = "longlong.md")]
-#[stable(feature = "raw_os", since = "1.1.0")]
-pub type c_longlong = i64;
-#[doc(include = "ulonglong.md")]
-#[stable(feature = "raw_os", since = "1.1.0")]
-pub type c_ulonglong = u64;
-#[doc(include = "float.md")]
-#[stable(feature = "raw_os", since = "1.1.0")]
-pub type c_float = f32;
-#[doc(include = "double.md")]
-#[stable(feature = "raw_os", since = "1.1.0")]
-pub type c_double = f64;
+)))]}
+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; #[cfg(any(target_pointer_width = "32", windows))] }
+type_alias! { "long.md", c_long = i64; #[cfg(all(target_pointer_width = "64", not(windows)))] }
+type_alias! { "ulong.md", c_ulong = u64; #[cfg(all(target_pointer_width = "64", not(windows)))] }
+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)]