From 2b483e78ff4e744e6aa5f29e02aa3735acd716f6 Mon Sep 17 00:00:00 2001
From: Joshua Liebow-Feeser <joshlf@google.com>
Date: Sun, 29 Jul 2018 17:13:25 -0700
Subject: [PATCH] Move std::os::raw into core

---
 src/libcore/lib.rs                          |   4 +
 src/libcore/os/mod.rs                       |  15 +++
 src/{libstd => libcore}/os/raw/char.md      |   0
 src/{libstd => libcore}/os/raw/double.md    |   0
 src/{libstd => libcore}/os/raw/float.md     |   0
 src/{libstd => libcore}/os/raw/int.md       |   0
 src/{libstd => libcore}/os/raw/long.md      |   0
 src/{libstd => libcore}/os/raw/longlong.md  |   0
 src/libcore/os/raw/mod.rs                   | 113 ++++++++++++++++++++
 src/{libstd => libcore}/os/raw/schar.md     |   0
 src/{libstd => libcore}/os/raw/short.md     |   0
 src/{libstd => libcore}/os/raw/uchar.md     |   0
 src/{libstd => libcore}/os/raw/uint.md      |   0
 src/{libstd => libcore}/os/raw/ulong.md     |   0
 src/{libstd => libcore}/os/raw/ulonglong.md |   0
 src/{libstd => libcore}/os/raw/ushort.md    |   0
 src/libstd/os/raw/mod.rs                    |  99 +----------------
 17 files changed, 135 insertions(+), 96 deletions(-)
 create mode 100644 src/libcore/os/mod.rs
 rename src/{libstd => libcore}/os/raw/char.md (100%)
 rename src/{libstd => libcore}/os/raw/double.md (100%)
 rename src/{libstd => libcore}/os/raw/float.md (100%)
 rename src/{libstd => libcore}/os/raw/int.md (100%)
 rename src/{libstd => libcore}/os/raw/long.md (100%)
 rename src/{libstd => libcore}/os/raw/longlong.md (100%)
 create mode 100644 src/libcore/os/raw/mod.rs
 rename src/{libstd => libcore}/os/raw/schar.md (100%)
 rename src/{libstd => libcore}/os/raw/short.md (100%)
 rename src/{libstd => libcore}/os/raw/uchar.md (100%)
 rename src/{libstd => libcore}/os/raw/uint.md (100%)
 rename src/{libstd => libcore}/os/raw/ulong.md (100%)
 rename src/{libstd => libcore}/os/raw/ulonglong.md (100%)
 rename src/{libstd => libcore}/os/raw/ushort.md (100%)

diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs
index 72074e1dbce18..eadb07b2c7cad 100644
--- a/src/libcore/lib.rs
+++ b/src/libcore/lib.rs
@@ -87,6 +87,7 @@
 #![feature(doc_cfg)]
 #![feature(doc_spotlight)]
 #![feature(extern_types)]
+#![feature(external_doc)]
 #![feature(fundamental)]
 #![feature(intrinsics)]
 #![feature(lang_items)]
@@ -205,6 +206,9 @@ pub mod time;
 
 pub mod unicode;
 
+/* OS-specific functionality */
+pub mod os;
+
 /* Async */
 pub mod future;
 pub mod task;
diff --git a/src/libcore/os/mod.rs b/src/libcore/os/mod.rs
new file mode 100644
index 0000000000000..2c62bcaa65613
--- /dev/null
+++ b/src/libcore/os/mod.rs
@@ -0,0 +1,15 @@
+// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! OS-specific functionality.
+
+#![stable(feature = "os", since = "1.29.0")]
+
+pub mod raw;
diff --git a/src/libstd/os/raw/char.md b/src/libcore/os/raw/char.md
similarity index 100%
rename from src/libstd/os/raw/char.md
rename to src/libcore/os/raw/char.md
diff --git a/src/libstd/os/raw/double.md b/src/libcore/os/raw/double.md
similarity index 100%
rename from src/libstd/os/raw/double.md
rename to src/libcore/os/raw/double.md
diff --git a/src/libstd/os/raw/float.md b/src/libcore/os/raw/float.md
similarity index 100%
rename from src/libstd/os/raw/float.md
rename to src/libcore/os/raw/float.md
diff --git a/src/libstd/os/raw/int.md b/src/libcore/os/raw/int.md
similarity index 100%
rename from src/libstd/os/raw/int.md
rename to src/libcore/os/raw/int.md
diff --git a/src/libstd/os/raw/long.md b/src/libcore/os/raw/long.md
similarity index 100%
rename from src/libstd/os/raw/long.md
rename to src/libcore/os/raw/long.md
diff --git a/src/libstd/os/raw/longlong.md b/src/libcore/os/raw/longlong.md
similarity index 100%
rename from src/libstd/os/raw/longlong.md
rename to src/libcore/os/raw/longlong.md
diff --git a/src/libcore/os/raw/mod.rs b/src/libcore/os/raw/mod.rs
new file mode 100644
index 0000000000000..235e5979775f7
--- /dev/null
+++ b/src/libcore/os/raw/mod.rs
@@ -0,0 +1,113 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! Platform-specific types, as defined by C.
+//!
+//! Code that interacts via FFI will almost certainly be using the
+//! base types provided by C, which aren't nearly as nicely defined
+//! as Rust's primitive types. This module provides types which will
+//! match those defined by C, so that code that interacts with C will
+//! refer to the correct types.
+
+#![stable(feature = "raw_os", since = "1.1.0")]
+
+use fmt;
+
+#[doc(include = "os/raw/char.md")]
+#[cfg(any(all(target_os = "linux", any(target_arch = "aarch64",
+                                       target_arch = "arm",
+                                       target_arch = "powerpc",
+                                       target_arch = "powerpc64",
+                                       target_arch = "s390x")),
+          all(target_os = "android", any(target_arch = "aarch64",
+                                         target_arch = "arm")),
+          all(target_os = "l4re", target_arch = "x86_64"),
+          all(target_os = "openbsd", target_arch = "aarch64"),
+          all(target_os = "fuchsia", target_arch = "aarch64")))]
+#[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = u8;
+#[doc(include = "os/raw/char.md")]
+#[cfg(not(any(all(target_os = "linux", any(target_arch = "aarch64",
+                                           target_arch = "arm",
+                                           target_arch = "powerpc",
+                                           target_arch = "powerpc64",
+                                           target_arch = "s390x")),
+              all(target_os = "android", any(target_arch = "aarch64",
+                                             target_arch = "arm")),
+              all(target_os = "l4re", target_arch = "x86_64"),
+              all(target_os = "openbsd", target_arch = "aarch64"),
+              all(target_os = "fuchsia", target_arch = "aarch64"))))]
+#[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = i8;
+#[doc(include = "os/raw/schar.md")]
+#[stable(feature = "raw_os", since = "1.1.0")] pub type c_schar = i8;
+#[doc(include = "os/raw/uchar.md")]
+#[stable(feature = "raw_os", since = "1.1.0")] pub type c_uchar = u8;
+#[doc(include = "os/raw/short.md")]
+#[stable(feature = "raw_os", since = "1.1.0")] pub type c_short = i16;
+#[doc(include = "os/raw/ushort.md")]
+#[stable(feature = "raw_os", since = "1.1.0")] pub type c_ushort = u16;
+#[doc(include = "os/raw/int.md")]
+#[stable(feature = "raw_os", since = "1.1.0")] pub type c_int = i32;
+#[doc(include = "os/raw/uint.md")]
+#[stable(feature = "raw_os", since = "1.1.0")] pub type c_uint = u32;
+#[doc(include = "os/raw/long.md")]
+#[cfg(any(target_pointer_width = "32", windows))]
+#[stable(feature = "raw_os", since = "1.1.0")] pub type c_long = i32;
+#[doc(include = "os/raw/ulong.md")]
+#[cfg(any(target_pointer_width = "32", windows))]
+#[stable(feature = "raw_os", since = "1.1.0")] pub type c_ulong = u32;
+#[doc(include = "os/raw/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 = "os/raw/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 = "os/raw/longlong.md")]
+#[stable(feature = "raw_os", since = "1.1.0")] pub type c_longlong = i64;
+#[doc(include = "os/raw/ulonglong.md")]
+#[stable(feature = "raw_os", since = "1.1.0")] pub type c_ulonglong = u64;
+#[doc(include = "os/raw/float.md")]
+#[stable(feature = "raw_os", since = "1.1.0")] pub type c_float = f32;
+#[doc(include = "os/raw/double.md")]
+#[stable(feature = "raw_os", since = "1.1.0")] pub type c_double = f64;
+
+/// Equivalent to C's `void` type when used as a [pointer].
+///
+/// In essence, `*const c_void` is equivalent to C's `const void*`
+/// and `*mut c_void` is equivalent to C's `void*`. That said, this is
+/// *not* the same as C's `void` return type, which is Rust's `()` type.
+///
+/// Ideally, this type would be equivalent to [`!`], but currently it may
+/// be more ideal to use `c_void` for FFI purposes.
+///
+/// [`!`]: ../../../std/primitive.never.html
+/// [pointer]: ../../../std/primitive.pointer.html
+// NB: For LLVM to recognize the void pointer type and by extension
+//     functions like malloc(), we need to have it represented as i8* in
+//     LLVM bitcode. The enum used here ensures this and prevents misuse
+//     of the "raw" type by only having private variants.. We need two
+//     variants, because the compiler complains about the repr attribute
+//     otherwise.
+#[repr(u8)]
+#[stable(feature = "raw_os", since = "1.1.0")]
+pub enum c_void {
+    #[unstable(feature = "c_void_variant", reason = "should not have to exist",
+               issue = "0")]
+    #[doc(hidden)] __variant1,
+    #[unstable(feature = "c_void_variant", reason = "should not have to exist",
+               issue = "0")]
+    #[doc(hidden)] __variant2,
+}
+
+#[stable(feature = "std_debug", since = "1.16.0")]
+impl fmt::Debug for c_void {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        f.pad("c_void")
+    }
+}
diff --git a/src/libstd/os/raw/schar.md b/src/libcore/os/raw/schar.md
similarity index 100%
rename from src/libstd/os/raw/schar.md
rename to src/libcore/os/raw/schar.md
diff --git a/src/libstd/os/raw/short.md b/src/libcore/os/raw/short.md
similarity index 100%
rename from src/libstd/os/raw/short.md
rename to src/libcore/os/raw/short.md
diff --git a/src/libstd/os/raw/uchar.md b/src/libcore/os/raw/uchar.md
similarity index 100%
rename from src/libstd/os/raw/uchar.md
rename to src/libcore/os/raw/uchar.md
diff --git a/src/libstd/os/raw/uint.md b/src/libcore/os/raw/uint.md
similarity index 100%
rename from src/libstd/os/raw/uint.md
rename to src/libcore/os/raw/uint.md
diff --git a/src/libstd/os/raw/ulong.md b/src/libcore/os/raw/ulong.md
similarity index 100%
rename from src/libstd/os/raw/ulong.md
rename to src/libcore/os/raw/ulong.md
diff --git a/src/libstd/os/raw/ulonglong.md b/src/libcore/os/raw/ulonglong.md
similarity index 100%
rename from src/libstd/os/raw/ulonglong.md
rename to src/libcore/os/raw/ulonglong.md
diff --git a/src/libstd/os/raw/ushort.md b/src/libcore/os/raw/ushort.md
similarity index 100%
rename from src/libstd/os/raw/ushort.md
rename to src/libcore/os/raw/ushort.md
diff --git a/src/libstd/os/raw/mod.rs b/src/libstd/os/raw/mod.rs
index d5eeb5252f0f1..5074cdc1c64a4 100644
--- a/src/libstd/os/raw/mod.rs
+++ b/src/libstd/os/raw/mod.rs
@@ -18,99 +18,8 @@
 
 #![stable(feature = "raw_os", since = "1.1.0")]
 
-use fmt;
-
-#[doc(include = "os/raw/char.md")]
-#[cfg(any(all(target_os = "linux", any(target_arch = "aarch64",
-                                       target_arch = "arm",
-                                       target_arch = "powerpc",
-                                       target_arch = "powerpc64",
-                                       target_arch = "s390x")),
-          all(target_os = "android", any(target_arch = "aarch64",
-                                         target_arch = "arm")),
-          all(target_os = "l4re", target_arch = "x86_64"),
-          all(target_os = "openbsd", target_arch = "aarch64"),
-          all(target_os = "fuchsia", target_arch = "aarch64")))]
-#[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = u8;
-#[doc(include = "os/raw/char.md")]
-#[cfg(not(any(all(target_os = "linux", any(target_arch = "aarch64",
-                                           target_arch = "arm",
-                                           target_arch = "powerpc",
-                                           target_arch = "powerpc64",
-                                           target_arch = "s390x")),
-              all(target_os = "android", any(target_arch = "aarch64",
-                                             target_arch = "arm")),
-              all(target_os = "l4re", target_arch = "x86_64"),
-              all(target_os = "openbsd", target_arch = "aarch64"),
-              all(target_os = "fuchsia", target_arch = "aarch64"))))]
-#[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = i8;
-#[doc(include = "os/raw/schar.md")]
-#[stable(feature = "raw_os", since = "1.1.0")] pub type c_schar = i8;
-#[doc(include = "os/raw/uchar.md")]
-#[stable(feature = "raw_os", since = "1.1.0")] pub type c_uchar = u8;
-#[doc(include = "os/raw/short.md")]
-#[stable(feature = "raw_os", since = "1.1.0")] pub type c_short = i16;
-#[doc(include = "os/raw/ushort.md")]
-#[stable(feature = "raw_os", since = "1.1.0")] pub type c_ushort = u16;
-#[doc(include = "os/raw/int.md")]
-#[stable(feature = "raw_os", since = "1.1.0")] pub type c_int = i32;
-#[doc(include = "os/raw/uint.md")]
-#[stable(feature = "raw_os", since = "1.1.0")] pub type c_uint = u32;
-#[doc(include = "os/raw/long.md")]
-#[cfg(any(target_pointer_width = "32", windows))]
-#[stable(feature = "raw_os", since = "1.1.0")] pub type c_long = i32;
-#[doc(include = "os/raw/ulong.md")]
-#[cfg(any(target_pointer_width = "32", windows))]
-#[stable(feature = "raw_os", since = "1.1.0")] pub type c_ulong = u32;
-#[doc(include = "os/raw/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 = "os/raw/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 = "os/raw/longlong.md")]
-#[stable(feature = "raw_os", since = "1.1.0")] pub type c_longlong = i64;
-#[doc(include = "os/raw/ulonglong.md")]
-#[stable(feature = "raw_os", since = "1.1.0")] pub type c_ulonglong = u64;
-#[doc(include = "os/raw/float.md")]
-#[stable(feature = "raw_os", since = "1.1.0")] pub type c_float = f32;
-#[doc(include = "os/raw/double.md")]
-#[stable(feature = "raw_os", since = "1.1.0")] pub type c_double = f64;
-
-/// Equivalent to C's `void` type when used as a [pointer].
-///
-/// In essence, `*const c_void` is equivalent to C's `const void*`
-/// and `*mut c_void` is equivalent to C's `void*`. That said, this is
-/// *not* the same as C's `void` return type, which is Rust's `()` type.
-///
-/// Ideally, this type would be equivalent to [`!`], but currently it may
-/// be more ideal to use `c_void` for FFI purposes.
-///
-/// [`!`]: ../../primitive.never.html
-/// [pointer]: ../../primitive.pointer.html
-// NB: For LLVM to recognize the void pointer type and by extension
-//     functions like malloc(), we need to have it represented as i8* in
-//     LLVM bitcode. The enum used here ensures this and prevents misuse
-//     of the "raw" type by only having private variants.. We need two
-//     variants, because the compiler complains about the repr attribute
-//     otherwise.
-#[repr(u8)]
 #[stable(feature = "raw_os", since = "1.1.0")]
-pub enum c_void {
-    #[unstable(feature = "c_void_variant", reason = "should not have to exist",
-               issue = "0")]
-    #[doc(hidden)] __variant1,
-    #[unstable(feature = "c_void_variant", reason = "should not have to exist",
-               issue = "0")]
-    #[doc(hidden)] __variant2,
-}
-
-#[stable(feature = "std_debug", since = "1.16.0")]
-impl fmt::Debug for c_void {
-    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        f.pad("c_void")
-    }
-}
+pub use ::core::os::raw::*;
 
 #[cfg(test)]
 #[allow(unused_imports)]
@@ -118,15 +27,13 @@ mod tests {
     use any::TypeId;
     use libc;
     use mem;
-
-    macro_rules! ok {
+     macro_rules! ok {
         ($($t:ident)*) => {$(
             assert!(TypeId::of::<libc::$t>() == TypeId::of::<raw::$t>(),
                     "{} is wrong", stringify!($t));
         )*}
     }
-
-    #[test]
+     #[test]
     fn same() {
         use os::raw;
         ok!(c_char c_schar c_uchar c_short c_ushort c_int c_uint c_long c_ulong