]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass/issue-20055-box-unsized-array.rs
Imported Upstream version 1.0.0~beta
[rustc.git] / src / test / run-pass / issue-20055-box-unsized-array.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // Issue #2005: Check that boxed fixed-size arrays are properly
12 // accounted for (namely, only deallocated if they were actually
13 // created) when they appear as temporaries in unused arms of a match
14 // expression.
15
16 pub fn foo(box_1: fn () -> Box<[i8; 1]>,
17 box_2: fn () -> Box<[i8; 20]>,
18 box_3: fn () -> Box<[i8; 300]>,
19 box_4: fn () -> Box<[i8; 4000]>,
20 ) {
21 println!("Hello World 1");
22 let _: Box<[i8]> = match 3 {
23 1 => box_1(),
24 2 => box_2(),
25 3 => box_3(),
26 _ => box_4(),
27 };
28 println!("Hello World 2");
29 }
30
31 pub fn main() {
32 fn box_1() -> Box<[i8; 1]> { Box::new( [1] ) }
33 fn box_2() -> Box<[i8; 20]> { Box::new( [1; 20] ) }
34 fn box_3() -> Box<[i8; 300]> { Box::new( [1; 300] ) }
35 fn box_4() -> Box<[i8; 4000]> { Box::new( [1; 4000] ) }
36
37 foo(box_1, box_2, box_3, box_4);
38 }