about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDodo <kasper199914@gmail.com>2020-03-02 21:05:14 +0100
committerDodo <kasper199914@gmail.com>2020-03-02 21:05:14 +0100
commit011fa9107f405149d006a4208ffb8503214e82ce (patch)
tree5e49fd4044365c5e70b86575f3d3db2ab035d197
parenta30b0a61b86c9742449837a2f5b669a7974fef5e (diff)
downloadrust-011fa9107f405149d006a4208ffb8503214e82ce.tar.gz
rust-011fa9107f405149d006a4208ffb8503214e82ce.zip
const forget tests
-rw-r--r--src/libcore/tests/lib.rs1
-rw-r--r--src/libcore/tests/mem.rs18
2 files changed, 19 insertions, 0 deletions
diff --git a/src/libcore/tests/lib.rs b/src/libcore/tests/lib.rs
index 991458db5b7..cc341c93980 100644
--- a/src/libcore/tests/lib.rs
+++ b/src/libcore/tests/lib.rs
@@ -40,6 +40,7 @@
 #![feature(never_type)]
 #![feature(unwrap_infallible)]
 #![feature(leading_trailing_ones)]
+#![feature(const_forget)]
 
 extern crate test;
 
diff --git a/src/libcore/tests/mem.rs b/src/libcore/tests/mem.rs
index 59588d97787..4841be5fc71 100644
--- a/src/libcore/tests/mem.rs
+++ b/src/libcore/tests/mem.rs
@@ -129,3 +129,21 @@ fn test_discriminant_send_sync() {
     is_send_sync::<Discriminant<Regular>>();
     is_send_sync::<Discriminant<NotSendSync>>();
 }
+
+#[test]
+fn test_const_forget() {
+    const fn test_const_forget<T>(x: T) {
+        forget(x);
+    }
+
+    // Writing this function signature without const-forget
+    // triggers compiler errors:
+    // 1) That we use a non-const fn inside a const fn
+    // 2) without the forget, it complains about the destructor of Box
+    const fn const_forget_box<T>(mut x: Box<T>) {
+        forget(x);
+    }
+
+    const _: () = test_const_forget(0i32);
+    const _: () = test_const_forget(Vec::<Vec<Box<i32>>>::new());
+}
\ No newline at end of file