8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
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
+
11
19
trait Boo { }
12
20
13
21
impl Boo for [ i8 ; 1 ] { }
@@ -16,12 +24,12 @@ impl Boo for [i8; 3] { }
16
24
impl Boo for [ i8 ; 4 ] { }
17
25
18
26
pub fn foo ( box_1 : fn ( ) -> Box < [ i8 ; 1 ] > ,
19
- box_2 : fn ( ) -> Box < [ i8 ; 20 ] > ,
20
- box_3 : fn ( ) -> Box < [ i8 ; 300 ] > ,
21
- box_4 : fn ( ) -> Box < [ i8 ; 4000 ] > ,
27
+ box_2 : fn ( ) -> Box < [ i8 ; 2 ] > ,
28
+ box_3 : fn ( ) -> Box < [ i8 ; 3 ] > ,
29
+ box_4 : fn ( ) -> Box < [ i8 ; 4 ] > ,
22
30
) {
23
31
println ! ( "Hello World 1" ) ;
24
- let _: Box < [ i8 ] > = match 3 {
32
+ let _: Box < Boo > = match 3 {
25
33
1 => box_1 ( ) ,
26
34
2 => box_2 ( ) ,
27
35
3 => box_3 ( ) ,
@@ -31,10 +39,10 @@ pub fn foo(box_1: fn () -> Box<[i8; 1]>,
31
39
}
32
40
33
41
pub fn main ( ) {
34
- fn box_1 ( ) -> Box < [ i8 ; 1 ] > { Box :: new ( [ 1i8 ] ) }
35
- fn box_2 ( ) -> Box < [ i8 ; 20 ] > { Box :: new ( [ 1i8 ; 20 ] ) }
36
- fn box_3 ( ) -> Box < [ i8 ; 300 ] > { Box :: new ( [ 1i8 ; 300 ] ) }
37
- fn box_4 ( ) -> Box < [ i8 ; 4000 ] > { Box :: new ( [ 1i8 ; 4000 ] ) }
42
+ fn box_1 ( ) -> Box < [ i8 ; 1 ] > { Box :: new ( [ 1i8 ; 1 ] ) }
43
+ fn box_2 ( ) -> Box < [ i8 ; 2 ] > { Box :: new ( [ 1i8 ; 2 ] ) }
44
+ fn box_3 ( ) -> Box < [ i8 ; 3 ] > { Box :: new ( [ 1i8 ; 3 ] ) }
45
+ fn box_4 ( ) -> Box < [ i8 ; 4 ] > { Box :: new ( [ 1i8 ; 4 ] ) }
38
46
39
47
foo ( box_1, box_2, box_3, box_4) ;
40
48
}
0 commit comments