Skip to content

Commit ae12272

Browse files
authored
Rollup merge of #69645 - DutchGhost:const-forget-tests, r=Dylan-DPC
const forget tests Adds tests for #69617
2 parents 25091ed + a674e1c commit ae12272

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
@@ -41,6 +41,7 @@
4141
#![feature(never_type)]
4242
#![feature(unwrap_infallible)]
4343
#![feature(leading_trailing_ones)]
44+
#![feature(const_forget)]
4445

4546
extern crate test;
4647

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 _: () = forget(0i32);
136+
const _: () = forget(Vec::<Vec<Box<i32>>>::new());
137+
138+
// Writing this function signature without const-forget
139+
// triggers compiler errors:
140+
// 1) That we use a non-const fn inside a const fn
141+
// 2) without the forget, it complains about the destructor of Box
142+
const fn const_forget_box<T>(x: Box<T>) {
143+
forget(x);
144+
}
145+
146+
// Call the forget_box at runtime,
147+
// as we can't const-construct a box yet.
148+
const_forget_box(Box::new(0i32));
149+
}

0 commit comments

Comments
 (0)