11// edition:2021
22
33#![ feature( rustc_attrs) ]
4+ #![ feature( stmt_expr_attributes) ]
45
56// Should capture the discriminant since a variant of a multivariant enum is
67// mentioned in the match arm; the discriminant is captured by the closure regardless
78// of if it creates a binding
89fn test_1_should_capture ( ) {
910 let variant = Some ( 2229 ) ;
1011 let c = #[ rustc_capture_analysis]
11- //~^ ERROR: attributes on expressions are experimental
12- //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
13-
1412 || {
1513 //~^ First Pass analysis includes:
1614 //~| Min Capture analysis includes:
@@ -29,8 +27,6 @@ fn test_1_should_capture() {
2927fn test_2_should_not_capture ( ) {
3028 let variant = Some ( 2229 ) ;
3129 let c = #[ rustc_capture_analysis]
32- //~^ ERROR: attributes on expressions are experimental
33- //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
3430 || {
3531 //~^ First Pass analysis includes:
3632 match variant {
@@ -50,8 +46,6 @@ enum SingleVariant {
5046fn test_3_should_not_capture_single_variant ( ) {
5147 let variant = SingleVariant :: Points ( 1 ) ;
5248 let c = #[ rustc_capture_analysis]
53- //~^ ERROR: attributes on expressions are experimental
54- //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
5549 || {
5650 //~^ First Pass analysis includes:
5751 match variant {
@@ -66,8 +60,6 @@ fn test_3_should_not_capture_single_variant() {
6660fn test_6_should_capture_single_variant ( ) {
6761 let variant = SingleVariant :: Points ( 1 ) ;
6862 let c = #[ rustc_capture_analysis]
69- //~^ ERROR: attributes on expressions are experimental
70- //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
7163 || {
7264 //~^ First Pass analysis includes:
7365 //~| Min Capture analysis includes:
@@ -88,8 +80,6 @@ fn test_6_should_capture_single_variant() {
8880fn test_4_should_not_capture_array ( ) {
8981 let array: [ i32 ; 3 ] = [ 0 ; 3 ] ;
9082 let c = #[ rustc_capture_analysis]
91- //~^ ERROR: attributes on expressions are experimental
92- //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
9383 || {
9484 //~^ First Pass analysis includes:
9585 match array {
@@ -112,8 +102,6 @@ enum MVariant {
112102fn test_5_should_capture_multi_variant ( ) {
113103 let variant = MVariant :: A ;
114104 let c = #[ rustc_capture_analysis]
115- //~^ ERROR: attributes on expressions are experimental
116- //~| NOTE: see issue #15701 <https://github.com/rust-lang/rust/issues/15701>
117105 || {
118106 //~^ First Pass analysis includes:
119107 //~| Min Capture analysis includes:
@@ -127,11 +115,69 @@ fn test_5_should_capture_multi_variant() {
127115 c ( ) ;
128116}
129117
118+ // Even though all patterns are wild, we need to read the discriminant
119+ // in order to test the slice length
120+ fn test_7_should_capture_slice_len ( ) {
121+ let slice: & [ i32 ] = & [ 1 , 2 , 3 ] ;
122+ let c = #[ rustc_capture_analysis]
123+ || {
124+ //~^ First Pass analysis includes:
125+ //~| Min Capture analysis includes:
126+ match slice {
127+ //~^ NOTE: Capturing slice[] -> ImmBorrow
128+ //~| NOTE: Min Capture slice[] -> ImmBorrow
129+ [ _, _, _] => { } ,
130+ _ => { }
131+ }
132+ } ;
133+ c ( ) ;
134+ let c = #[ rustc_capture_analysis]
135+ || {
136+ //~^ First Pass analysis includes:
137+ //~| Min Capture analysis includes:
138+ match slice {
139+ //~^ NOTE: Capturing slice[] -> ImmBorrow
140+ //~| NOTE: Min Capture slice[] -> ImmBorrow
141+ [ ] => { } ,
142+ _ => { }
143+ }
144+ } ;
145+ c ( ) ;
146+ let c = #[ rustc_capture_analysis]
147+ || {
148+ //~^ First Pass analysis includes:
149+ //~| Min Capture analysis includes:
150+ match slice {
151+ //~^ NOTE: Capturing slice[] -> ImmBorrow
152+ //~| NOTE: Min Capture slice[] -> ImmBorrow
153+ [ _, .. , _] => { } ,
154+ _ => { }
155+ }
156+ } ;
157+ c ( ) ;
158+ }
159+
160+ // Wild pattern that doesn't bind, so no capture
161+ fn test_8_capture_slice_wild ( ) {
162+ let slice: & [ i32 ] = & [ 1 , 2 , 3 ] ;
163+ let c = #[ rustc_capture_analysis]
164+ || {
165+ //~^ First Pass analysis includes:
166+ match slice {
167+ [ ..] => { } ,
168+ _ => { }
169+ }
170+ } ;
171+ c ( ) ;
172+ }
173+
130174fn main ( ) {
131175 test_1_should_capture ( ) ;
132176 test_2_should_not_capture ( ) ;
133177 test_3_should_not_capture_single_variant ( ) ;
134178 test_6_should_capture_single_variant ( ) ;
135179 test_4_should_not_capture_array ( ) ;
136180 test_5_should_capture_multi_variant ( ) ;
181+ test_7_should_capture_slice_len ( ) ;
182+ test_8_capture_slice_wild ( ) ;
137183}
0 commit comments