about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTomasz Miąsko <tomasz.miasko@gmail.com>2020-12-29 00:00:00 +0000
committerTomasz Miąsko <tomasz.miasko@gmail.com>2020-12-29 00:00:00 +0000
commit5718cc2f9b32290dc34ce320076f92d90c00fb7d (patch)
tree1fbd30e642e861f19c4cc6fe44df9c16ce740be5
parent158f8d034b15e65ba8dc0d066358dd0632bfcd6e (diff)
downloadrust-5718cc2f9b32290dc34ce320076f92d90c00fb7d.tar.gz
rust-5718cc2f9b32290dc34ce320076f92d90c00fb7d.zip
Make forget intrinsic safe
-rw-r--r--compiler/rustc_typeck/src/check/intrinsic.rs1
-rw-r--r--library/core/src/mem/mod.rs7
-rw-r--r--src/test/mir-opt/lower_intrinsics.forget.LowerIntrinsics.diff24
-rw-r--r--src/test/mir-opt/lower_intrinsics.rs2
4 files changed, 17 insertions, 17 deletions
diff --git a/compiler/rustc_typeck/src/check/intrinsic.rs b/compiler/rustc_typeck/src/check/intrinsic.rs
index c3b0fc60b97..673dec6c7f9 100644
--- a/compiler/rustc_typeck/src/check/intrinsic.rs
+++ b/compiler/rustc_typeck/src/check/intrinsic.rs
@@ -92,6 +92,7 @@ pub fn intrinsic_operation_unsafety(intrinsic: Symbol) -> hir::Unsafety {
         | sym::rustc_peek
         | sym::maxnumf64
         | sym::type_name
+        | sym::forget
         | sym::variant_count => hir::Unsafety::Normal,
         _ => hir::Unsafety::Unsafe,
     }
diff --git a/library/core/src/mem/mod.rs b/library/core/src/mem/mod.rs
index e84014c68a6..87956787242 100644
--- a/library/core/src/mem/mod.rs
+++ b/library/core/src/mem/mod.rs
@@ -151,9 +151,14 @@ pub const fn forget<T>(t: T) {
 #[inline]
 #[unstable(feature = "forget_unsized", issue = "none")]
 pub fn forget_unsized<T: ?Sized>(t: T) {
+    #[cfg(bootstrap)]
     // SAFETY: the forget intrinsic could be safe, but there's no point in making it safe since
     // we'll be implementing this function soon via `ManuallyDrop`
-    unsafe { intrinsics::forget(t) }
+    unsafe {
+        intrinsics::forget(t)
+    }
+    #[cfg(not(bootstrap))]
+    intrinsics::forget(t)
 }
 
 /// Returns the size of a type in bytes.
diff --git a/src/test/mir-opt/lower_intrinsics.forget.LowerIntrinsics.diff b/src/test/mir-opt/lower_intrinsics.forget.LowerIntrinsics.diff
index e9cc72f2138..096bba64c0b 100644
--- a/src/test/mir-opt/lower_intrinsics.forget.LowerIntrinsics.diff
+++ b/src/test/mir-opt/lower_intrinsics.forget.LowerIntrinsics.diff
@@ -4,27 +4,21 @@
   fn forget(_1: T) -> () {
       debug t => _1;                       // in scope 0 at $DIR/lower_intrinsics.rs:18:18: 18:19
       let mut _0: ();                      // return place in scope 0 at $DIR/lower_intrinsics.rs:18:24: 18:24
-      let _2: ();                          // in scope 0 at $DIR/lower_intrinsics.rs:19:14: 19:41
-      let mut _3: T;                       // in scope 0 at $DIR/lower_intrinsics.rs:19:39: 19:40
-      scope 1 {
-      }
+      let mut _2: T;                       // in scope 0 at $DIR/lower_intrinsics.rs:19:30: 19:31
   
       bb0: {
-          StorageLive(_2);                 // scope 0 at $DIR/lower_intrinsics.rs:19:5: 19:43
-          StorageLive(_3);                 // scope 1 at $DIR/lower_intrinsics.rs:19:39: 19:40
-          _3 = move _1;                    // scope 1 at $DIR/lower_intrinsics.rs:19:39: 19:40
--         _2 = std::intrinsics::forget::<T>(move _3) -> bb1; // scope 1 at $DIR/lower_intrinsics.rs:19:14: 19:41
+          StorageLive(_2);                 // scope 0 at $DIR/lower_intrinsics.rs:19:30: 19:31
+          _2 = move _1;                    // scope 0 at $DIR/lower_intrinsics.rs:19:30: 19:31
+-         _0 = std::intrinsics::forget::<T>(move _2) -> bb1; // scope 0 at $DIR/lower_intrinsics.rs:19:5: 19:32
 -                                          // mir::Constant
--                                          // + span: $DIR/lower_intrinsics.rs:19:14: 19:38
--                                          // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(T) {std::intrinsics::forget::<T>}, val: Value(Scalar(<ZST>)) }
-+         _2 = const ();                   // scope 1 at $DIR/lower_intrinsics.rs:19:14: 19:41
-+         goto -> bb1;                     // scope 1 at $DIR/lower_intrinsics.rs:19:14: 19:41
+-                                          // + span: $DIR/lower_intrinsics.rs:19:5: 19:29
+-                                          // + literal: Const { ty: extern "rust-intrinsic" fn(T) {std::intrinsics::forget::<T>}, val: Value(Scalar(<ZST>)) }
++         _0 = const ();                   // scope 0 at $DIR/lower_intrinsics.rs:19:5: 19:32
++         goto -> bb1;                     // scope 0 at $DIR/lower_intrinsics.rs:19:5: 19:32
       }
   
       bb1: {
-          StorageDead(_3);                 // scope 1 at $DIR/lower_intrinsics.rs:19:40: 19:41
-          StorageDead(_2);                 // scope 0 at $DIR/lower_intrinsics.rs:19:43: 19:44
-          _0 = const ();                   // scope 0 at $DIR/lower_intrinsics.rs:18:24: 20:2
+          StorageDead(_2);                 // scope 0 at $DIR/lower_intrinsics.rs:19:31: 19:32
           goto -> bb2;                     // scope 0 at $DIR/lower_intrinsics.rs:20:1: 20:2
       }
   
diff --git a/src/test/mir-opt/lower_intrinsics.rs b/src/test/mir-opt/lower_intrinsics.rs
index 8d28354a5f1..d9891465dab 100644
--- a/src/test/mir-opt/lower_intrinsics.rs
+++ b/src/test/mir-opt/lower_intrinsics.rs
@@ -16,7 +16,7 @@ pub fn size_of<T>() -> usize {
 
 // EMIT_MIR lower_intrinsics.forget.LowerIntrinsics.diff
 pub fn forget<T>(t: T) {
-    unsafe { core::intrinsics::forget(t) };
+    core::intrinsics::forget(t)
 }
 
 // EMIT_MIR lower_intrinsics.unreachable.LowerIntrinsics.diff