]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-20055-box-unsized-array.rs
:arrow_up: rust-analyzer
[rust.git] / src / test / ui / issues / issue-20055-box-unsized-array.rs
1 // run-pass
2 // Issue #2005: Check that boxed fixed-size arrays are properly
3 // accounted for (namely, only deallocated if they were actually
4 // created) when they appear as temporaries in unused arms of a match
5 // expression.
6
7 pub fn foo(box_1: fn () -> Box<[i8; 1]>,
8            box_2: fn () -> Box<[i8; 20]>,
9            box_3: fn () -> Box<[i8; 300]>,
10            box_4: fn () -> Box<[i8; 4000]>,
11             ) {
12     println!("Hello World 1");
13     let _: Box<[i8]> = match 3 {
14         1 => box_1(),
15         2 => box_2(),
16         3 => box_3(),
17         _ => box_4(),
18     };
19     println!("Hello World 2");
20 }
21
22 pub fn main() {
23     fn box_1() -> Box<[i8; 1]> { Box::new( [1] ) }
24     fn box_2() -> Box<[i8; 20]> { Box::new( [1; 20] ) }
25     fn box_3() -> Box<[i8; 300]> { Box::new( [1; 300] ) }
26     fn box_4() -> Box<[i8; 4000]> { Box::new( [1; 4000] ) }
27
28     foo(box_1, box_2, box_3, box_4);
29 }