88// option. This file may not be copied, modified, or distributed
99// except according to those terms.
1010
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+
1119trait Boo { }
1220
1321impl Boo for [ i8 ; 1 ] { }
@@ -16,12 +24,12 @@ impl Boo for [i8; 3] { }
1624impl Boo for [ i8 ; 4 ] { }
1725
1826pub 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 ] > ,
2230 ) {
2331 println ! ( "Hello World 1" ) ;
24- let _: Box < [ i8 ] > = match 3 {
32+ let _: Box < Boo > = match 3 {
2533 1 => box_1 ( ) ,
2634 2 => box_2 ( ) ,
2735 3 => box_3 ( ) ,
@@ -31,10 +39,10 @@ pub fn foo(box_1: fn () -> Box<[i8; 1]>,
3139}
3240
3341pub 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 ] ) }
3846
3947 foo ( box_1, box_2, box_3, box_4) ;
4048}
0 commit comments