const forget tests

This commit is contained in:
Dodo 2020-03-02 21:05:14 +01:00
parent a30b0a61b8
commit 011fa9107f
2 changed files with 19 additions and 0 deletions

View file

@ -40,6 +40,7 @@
#![feature(never_type)]
#![feature(unwrap_infallible)]
#![feature(leading_trailing_ones)]
#![feature(const_forget)]
extern crate test;

View file

@ -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());
}