]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass/issue-20055-box-trait.rs
Imported Upstream version 1.0.0~beta
[rustc.git] / src / test / run-pass / issue-20055-box-trait.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 // See Issues #20055 and #21695.
12
13 // We are checking here that the temporaries `Box<[i8, k]>`, for `k`
14 // in 1, 2, 3, 4, that are induced by the match expression are
15 // properly handled, in that only *one* will be initialized by
16 // whichever arm is run, and subsequently dropped at the end of the
17 // statement surrounding the `match`.
18
19 trait Boo {
20 fn dummy(&self) { }
21 }
22
23 impl Boo for [i8; 1] { }
24 impl Boo for [i8; 2] { }
25 impl Boo for [i8; 3] { }
26 impl Boo for [i8; 4] { }
27
28 pub fn foo(box_1: fn () -> Box<[i8; 1]>,
29 box_2: fn () -> Box<[i8; 2]>,
30 box_3: fn () -> Box<[i8; 3]>,
31 box_4: fn () -> Box<[i8; 4]>,
32 ) {
33 println!("Hello World 1");
34 let _: Box<Boo> = match 3 {
35 1 => box_1(),
36 2 => box_2(),
37 3 => box_3(),
38 _ => box_4(),
39 };
40 println!("Hello World 2");
41 }
42
43 pub fn main() {
44 fn box_1() -> Box<[i8; 1]> { Box::new( [1; 1] ) }
45 fn box_2() -> Box<[i8; 2]> { Box::new( [1; 2] ) }
46 fn box_3() -> Box<[i8; 3]> { Box::new( [1; 3] ) }
47 fn box_4() -> Box<[i8; 4]> { Box::new( [1; 4] ) }
48
49 foo(box_1, box_2, box_3, box_4);
50 }