From edb45421398466f73b59a9da45ea8f521adf5fcd Mon Sep 17 00:00:00 2001 From: Scott McMurray Date: Sun, 13 Dec 2020 21:36:21 -0800 Subject: [PATCH] Add a test using `mem::forget` in a `const fn` --- library/core/tests/mem.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/library/core/tests/mem.rs b/library/core/tests/mem.rs index 268c2ed283f64..54e90387b36e2 100644 --- a/library/core/tests/mem.rs +++ b/library/core/tests/mem.rs @@ -137,3 +137,16 @@ fn assume_init_good() { assert!(TRUE); } + +#[test] +#[cfg(not(bootstrap))] +fn forget_works_in_const_fn() { + const fn forget_arg_and_return_4(x: Vec) -> i32 { + std::mem::forget(x); + 4 + } + + const FOUR_THE_HARD_WAY: i32 = forget_arg_and_return_4(Vec::new()); + + assert_eq!(FOUR_THE_HARD_WAY, 4); +}