From 57b1e7a428c16a1b692b88cc25ce8b09d8ea503b Mon Sep 17 00:00:00 2001 From: DutchGhost <kasper199914@gmail.com> Date: Mon, 16 Mar 2020 10:51:00 +0100 Subject: [PATCH 1/5] Remove the call that makes miri fail --- src/libcore/tests/mem.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/libcore/tests/mem.rs b/src/libcore/tests/mem.rs index 8337ab10341..2329bf97ff5 100644 --- a/src/libcore/tests/mem.rs +++ b/src/libcore/tests/mem.rs @@ -142,8 +142,4 @@ fn test_const_forget() { const fn const_forget_box<T>(x: Box<T>) { forget(x); } - - // Call the forget_box at runtime, - // as we can't const-construct a box yet. - const_forget_box(Box::new(0i32)); } From dcc23217b7364056d5a83aaa058993ccd83b6e78 Mon Sep 17 00:00:00 2001 From: DutchGhost <kasper199914@gmail.com> Date: Mon, 16 Mar 2020 13:24:59 +0100 Subject: [PATCH 2/5] The const_forget_box was unused, and doesns't add anything to test by itself. --- src/libcore/tests/mem.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/libcore/tests/mem.rs b/src/libcore/tests/mem.rs index 2329bf97ff5..1502c9ac375 100644 --- a/src/libcore/tests/mem.rs +++ b/src/libcore/tests/mem.rs @@ -134,12 +134,4 @@ fn test_discriminant_send_sync() { fn test_const_forget() { const _: () = forget(0i32); const _: () = forget(Vec::<Vec<Box<i32>>>::new()); - - // 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>(x: Box<T>) { - forget(x); - } } From 0760803c06ff4128405ea22e390625938a15bcb2 Mon Sep 17 00:00:00 2001 From: DutchGhost <kasper199914@gmail.com> Date: Mon, 16 Mar 2020 14:45:37 +0100 Subject: [PATCH 3/5] rather than removing const_forget_box, stick an attribute on it and explain it cant be called in ctfe yet --- src/libcore/tests/mem.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/libcore/tests/mem.rs b/src/libcore/tests/mem.rs index 1502c9ac375..ab6f08fb3ad 100644 --- a/src/libcore/tests/mem.rs +++ b/src/libcore/tests/mem.rs @@ -134,4 +134,16 @@ fn test_discriminant_send_sync() { fn test_const_forget() { const _: () = forget(0i32); const _: () = forget(Vec::<Vec<Box<i32>>>::new()); + + // 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 + // + // FIXME: this method cannot be called in const-eval yet, as Box isn't + // const constructable + #[allow(unused)] + const fn const_forget_box<T: ?Sized>(x: Box<T>) { + forget(x); + } } From 4c363e3e8af35c8e45333b522cb0d7b1a284c665 Mon Sep 17 00:00:00 2001 From: DutchGhost <kasper199914@gmail.com> Date: Wed, 18 Mar 2020 21:08:52 +0100 Subject: [PATCH 4/5] Move the const-forget test into ui tests --- src/libcore/tests/mem.rs | 18 ------------------ src/test/ui/consts/const_forget.rs | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+), 18 deletions(-) create mode 100644 src/test/ui/consts/const_forget.rs diff --git a/src/libcore/tests/mem.rs b/src/libcore/tests/mem.rs index ab6f08fb3ad..59588d97787 100644 --- a/src/libcore/tests/mem.rs +++ b/src/libcore/tests/mem.rs @@ -129,21 +129,3 @@ fn test_discriminant_send_sync() { is_send_sync::<Discriminant<Regular>>(); is_send_sync::<Discriminant<NotSendSync>>(); } - -#[test] -fn test_const_forget() { - const _: () = forget(0i32); - const _: () = forget(Vec::<Vec<Box<i32>>>::new()); - - // 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 - // - // FIXME: this method cannot be called in const-eval yet, as Box isn't - // const constructable - #[allow(unused)] - const fn const_forget_box<T: ?Sized>(x: Box<T>) { - forget(x); - } -} diff --git a/src/test/ui/consts/const_forget.rs b/src/test/ui/consts/const_forget.rs new file mode 100644 index 00000000000..5dcad9be54f --- /dev/null +++ b/src/test/ui/consts/const_forget.rs @@ -0,0 +1,22 @@ +// run-pass + +#![feature(const_forget)] + +use std::mem::forget; + +const _: () = forget(0i32); +const _: () = forget(Vec::<Vec<Box<i32>>>::new()); + +// 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 +// +// FIXME: this method cannot be called in const-eval yet, as Box isn't +// const constructable +#[allow(unused)] +const fn const_forget_box<T: ?Sized>(b: Box<T>) { + forget(b); +} + +fn main() {} From d6f3a433d9847b2c4c6c31f9ea985625b16dded1 Mon Sep 17 00:00:00 2001 From: DutchGhost <kasper199914@gmail.com> Date: Fri, 20 Mar 2020 10:36:40 +0100 Subject: [PATCH 5/5] Update const_forget.rs --- src/test/ui/consts/const_forget.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/ui/consts/const_forget.rs b/src/test/ui/consts/const_forget.rs index 5dcad9be54f..2dcb72a5a09 100644 --- a/src/test/ui/consts/const_forget.rs +++ b/src/test/ui/consts/const_forget.rs @@ -1,4 +1,4 @@ -// run-pass +// check-pass #![feature(const_forget)]