From 7f3e18cc2b24214e10df5434972f4f7cd461fa98 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 28 Nov 2020 17:32:48 +0100 Subject: [PATCH] make sure [CONST; N] drops N times --- .../const-repeat.rs | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/const-repeat.rs b/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/const-repeat.rs index 11611a949187..65d02317d34c 100644 --- a/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/const-repeat.rs +++ b/src/test/ui/consts/rfc-2203-const-array-repeat-exprs/const-repeat.rs @@ -1,4 +1,4 @@ -// check-pass +// run-pass // Repeating a *constant* of non-Copy type (not just a constant expression) is already stable. @@ -8,6 +8,20 @@ pub fn bar() -> [Vec; 2] { [EMPTY; 2] } -fn main() { - let x = bar(); +struct Bomb; + +impl Drop for Bomb { + fn drop(&mut self) { + panic!("BOOM!"); + } +} + +const BOOM: Bomb = Bomb; + +fn main() { + let _x = bar(); + + // Make sure the destructor does not get called for empty arrays. `[CONST; N]` should + // instantiate (and then later drop) the const exactly `N` times. + let _x = [BOOM; 0]; }