about summary refs log tree commit diff
path: root/example
diff options
context:
space:
mode:
authorbjorn3 <bjorn3@users.noreply.github.com>2019-02-24 16:46:11 +0100
committerbjorn3 <bjorn3@users.noreply.github.com>2019-04-10 17:25:57 +0200
commit970d164089f0cc2dc90dafeb3eedb681d505dc81 (patch)
treea340199be12c8e664db05b76df4952529289176b /example
parent16f41266567b16924cd0dff66122db041cc613a5 (diff)
downloadrust-970d164089f0cc2dc90dafeb3eedb681d505dc81.tar.gz
rust-970d164089f0cc2dc90dafeb3eedb681d505dc81.zip
Fix and optimize init intrinsic
Diffstat (limited to 'example')
-rw-r--r--example/mini_core.rs1
-rw-r--r--example/mini_core_hello_world.rs23
2 files changed, 24 insertions, 0 deletions
diff --git a/example/mini_core.rs b/example/mini_core.rs
index ffc2cd8fb65..dd42257b194 100644
--- a/example/mini_core.rs
+++ b/example/mini_core.rs
@@ -371,6 +371,7 @@ pub mod intrinsics {
         pub fn copy<T>(src: *const T, dst: *mut T, count: usize);
         pub fn transmute<T, U>(e: T) -> U;
         pub fn uninit<T>() -> T;
+        pub fn init<T>() -> T;
         pub fn ctlz_nonzero<T>(x: T) -> T;
         pub fn needs_drop<T>() -> bool;
         pub fn bitreverse<T>(x: T) -> T;
diff --git a/example/mini_core_hello_world.rs b/example/mini_core_hello_world.rs
index e69c509b763..fdd26f8791d 100644
--- a/example/mini_core_hello_world.rs
+++ b/example/mini_core_hello_world.rs
@@ -165,6 +165,29 @@ fn main() {
         struct MyDst<T: ?Sized>(T);
 
         intrinsics::size_of_val(&MyDst([0u8; 4]) as &MyDst<[u8]>);
+
+        struct Foo {
+            x: u8,
+            y: !,
+        }
+
+        unsafe fn zeroed<T>() -> T {
+            intrinsics::init::<T>()
+        }
+
+        unsafe fn uninitialized<T>() -> T {
+            intrinsics::uninit::<T>()
+        }
+
+        #[allow(unreachable_code)]
+        {
+            if false {
+                zeroed::<!>();
+                zeroed::<Foo>();
+                zeroed::<(u8, u8)>();
+                uninitialized::<Foo>();
+            }
+        }
     }
 
     let _ = box NoisyDrop {