]> git.lizzy.rs Git - rust.git/blobdiff - example/mini_core_hello_world.rs
Rustup to rustc 1.45.0-nightly (56daaf669 2020-06-03)
[rust.git] / example / mini_core_hello_world.rs
index 489ceea83ea195afb81f5387eb1b285b98b90894..82014f594d23bb043504b751aae4da759f88c548 100644 (file)
@@ -1,7 +1,7 @@
 // Adapted from https://github.com/sunfishcode/mir2cranelift/blob/master/rust-examples/nocore-hello-world.rs
 
 #![feature(
-    no_core, unboxed_closures, start, lang_items, box_syntax, slice_patterns, never_type, linkage,
+    no_core, unboxed_closures, start, lang_items, box_syntax, never_type, linkage,
     extern_types, thread_local
 )]
 #![no_core]
@@ -97,7 +97,7 @@ fn start<T: Termination + 'static>(
 macro_rules! assert {
     ($e:expr) => {
         if !$e {
-            panic(&(stringify!(! $e), file!(), line!(), 0));
+            panic(stringify!(! $e));
         }
     };
 }
@@ -105,7 +105,7 @@ macro_rules! assert {
 macro_rules! assert_eq {
     ($l:expr, $r: expr) => {
         if $l != $r {
-            panic(&(stringify!($l != $r), file!(), line!(), 0));
+            panic(stringify!($l != $r));
         }
     }
 }
@@ -117,6 +117,12 @@ struct Unique<T: ?Sized> {
 
 impl<T: ?Sized, U: ?Sized> CoerceUnsized<Unique<U>> for Unique<T> where T: Unsize<U> {}
 
+unsafe fn zeroed<T>() -> T {
+    let mut uninit = MaybeUninit { uninit: () };
+    intrinsics::write_bytes(&mut uninit.value.value as *mut T, 0, 1);
+    uninit.value.value
+}
+
 fn take_f32(_f: f32) {}
 fn take_unique(_u: Unique<()>) {}
 
@@ -194,10 +200,6 @@ struct Foo {
             y: !,
         }
 
-        unsafe fn zeroed<T>() -> T {
-            intrinsics::init::<T>()
-        }
-
         unsafe fn uninitialized<T>() -> T {
             MaybeUninit { uninit: () }.value.value
         }
@@ -330,7 +332,7 @@ extern "C" fn mutate_tls(_: *mut c_void) -> *mut c_void {
 #[cfg(not(jit))]
 fn test_tls() {
     unsafe {
-        let mut attr: pthread_attr_t = intrinsics::init();
+        let mut attr: pthread_attr_t = zeroed();
         let mut thread: pthread_t = 0;
 
         assert_eq!(TLS, 42);
@@ -412,10 +414,10 @@ pub enum E2<X> {
 
 fn check_niche_behavior () {
     if let E1::V2 { .. } = (E1::V1 { f: true }) {
-        unsafe { intrinsics::abort(); }
+        intrinsics::abort();
     }
 
     if let E2::V1 { .. } = E2::V3::<Infallible> {
-        unsafe { intrinsics::abort(); }
+        intrinsics::abort();
     }
 }