]> git.lizzy.rs Git - rust.git/commitdiff
const forget tests
authorDodo <kasper199914@gmail.com>
Mon, 2 Mar 2020 20:05:14 +0000 (21:05 +0100)
committerDodo <kasper199914@gmail.com>
Mon, 2 Mar 2020 20:05:14 +0000 (21:05 +0100)
src/libcore/tests/lib.rs
src/libcore/tests/mem.rs

index 991458db5b72bde21de92bdfe382734559a0f495..cc341c939803e7af13ca3f92adb5fcf7cb7e0c94 100644 (file)
@@ -40,6 +40,7 @@
 #![feature(never_type)]
 #![feature(unwrap_infallible)]
 #![feature(leading_trailing_ones)]
+#![feature(const_forget)]
 
 extern crate test;
 
index 59588d97787b7adc19a93b15b83868fe8f980614..4841be5fc71075cb79246d73476572b42ea2e3ca 100644 (file)
@@ -129,3 +129,21 @@ fn is_send_sync<T: 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