]> git.proxmox.com Git - rustc.git/blob - tests/ui/issues/issue-20055-box-trait.rs
New upstream version 1.68.2+dfsg1
[rustc.git] / tests / ui / issues / issue-20055-box-trait.rs
1 // run-pass
2 // See Issues #20055 and #21695.
3
4 // We are checking here that the temporaries `Box<[i8, k]>`, for `k`
5 // in 1, 2, 3, 4, that are induced by the match expression are
6 // properly handled, in that only *one* will be initialized by
7 // whichever arm is run, and subsequently dropped at the end of the
8 // statement surrounding the `match`.
9
10 trait Boo {
11 fn dummy(&self) { }
12 }
13
14 impl Boo for [i8; 1] { }
15 impl Boo for [i8; 2] { }
16 impl Boo for [i8; 3] { }
17 impl Boo for [i8; 4] { }
18
19 pub fn foo(box_1: fn () -> Box<[i8; 1]>,
20 box_2: fn () -> Box<[i8; 2]>,
21 box_3: fn () -> Box<[i8; 3]>,
22 box_4: fn () -> Box<[i8; 4]>,
23 ) {
24 println!("Hello World 1");
25 let _: Box<dyn Boo> = match 3 {
26 1 => box_1(),
27 2 => box_2(),
28 3 => box_3(),
29 _ => box_4(),
30 };
31 println!("Hello World 2");
32 }
33
34 pub fn main() {
35 fn box_1() -> Box<[i8; 1]> { Box::new( [1; 1] ) }
36 fn box_2() -> Box<[i8; 2]> { Box::new( [1; 2] ) }
37 fn box_3() -> Box<[i8; 3]> { Box::new( [1; 3] ) }
38 fn box_4() -> Box<[i8; 4]> { Box::new( [1; 4] ) }
39
40 foo(box_1, box_2, box_3, box_4);
41 }