Skip to content

Commit

Permalink
make sure [CONST; N] drops N times
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Dec 20, 2020
1 parent f8d4883 commit 7f3e18c
Showing 1 changed file with 16 additions and 2 deletions.
@@ -1,4 +1,4 @@
// check-pass
// run-pass

// Repeating a *constant* of non-Copy type (not just a constant expression) is already stable.

Expand All @@ -8,6 +8,20 @@ pub fn bar() -> [Vec<i32>; 2] {
[EMPTY; 2]
}

struct Bomb;

impl Drop for Bomb {
fn drop(&mut self) {
panic!("BOOM!");
}
}

const BOOM: Bomb = Bomb;

fn main() {
let x = bar();
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];
}

0 comments on commit 7f3e18c

Please sign in to comment.