Skip to content

Commit 011fa91

Browse files
committed
const forget tests
1 parent a30b0a6 commit 011fa91

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/libcore/tests/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#![feature(never_type)]
4141
#![feature(unwrap_infallible)]
4242
#![feature(leading_trailing_ones)]
43+
#![feature(const_forget)]
4344

4445
extern crate test;
4546

src/libcore/tests/mem.rs

+18
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,21 @@ fn test_discriminant_send_sync() {
129129
is_send_sync::<Discriminant<Regular>>();
130130
is_send_sync::<Discriminant<NotSendSync>>();
131131
}
132+
133+
#[test]
134+
fn test_const_forget() {
135+
const fn test_const_forget<T>(x: T) {
136+
forget(x);
137+
}
138+
139+
// Writing this function signature without const-forget
140+
// triggers compiler errors:
141+
// 1) That we use a non-const fn inside a const fn
142+
// 2) without the forget, it complains about the destructor of Box
143+
const fn const_forget_box<T>(mut x: Box<T>) {
144+
forget(x);
145+
}
146+
147+
const _: () = test_const_forget(0i32);
148+
const _: () = test_const_forget(Vec::<Vec<Box<i32>>>::new());
149+
}

0 commit comments

Comments
 (0)