1
1
// edition:2021
2
2
3
3
#![ feature( rustc_attrs) ]
4
+ #![ feature( stmt_expr_attributes) ]
4
5
5
6
// Should capture the discriminant since a variant of a multivariant enum is
6
7
// mentioned in the match arm; the discriminant is captured by the closure regardless
7
8
// of if it creates a binding
8
9
fn test_1_should_capture ( ) {
9
10
let variant = Some ( 2229 ) ;
10
11
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
-
14
12
|| {
15
13
//~^ First Pass analysis includes:
16
14
//~| Min Capture analysis includes:
@@ -29,8 +27,6 @@ fn test_1_should_capture() {
29
27
fn test_2_should_not_capture ( ) {
30
28
let variant = Some ( 2229 ) ;
31
29
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>
34
30
|| {
35
31
//~^ First Pass analysis includes:
36
32
match variant {
@@ -50,8 +46,6 @@ enum SingleVariant {
50
46
fn test_3_should_not_capture_single_variant ( ) {
51
47
let variant = SingleVariant :: Points ( 1 ) ;
52
48
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>
55
49
|| {
56
50
//~^ First Pass analysis includes:
57
51
match variant {
@@ -66,8 +60,6 @@ fn test_3_should_not_capture_single_variant() {
66
60
fn test_6_should_capture_single_variant ( ) {
67
61
let variant = SingleVariant :: Points ( 1 ) ;
68
62
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>
71
63
|| {
72
64
//~^ First Pass analysis includes:
73
65
//~| Min Capture analysis includes:
@@ -88,8 +80,6 @@ fn test_6_should_capture_single_variant() {
88
80
fn test_4_should_not_capture_array ( ) {
89
81
let array: [ i32 ; 3 ] = [ 0 ; 3 ] ;
90
82
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>
93
83
|| {
94
84
//~^ First Pass analysis includes:
95
85
match array {
@@ -112,8 +102,6 @@ enum MVariant {
112
102
fn test_5_should_capture_multi_variant ( ) {
113
103
let variant = MVariant :: A ;
114
104
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>
117
105
|| {
118
106
//~^ First Pass analysis includes:
119
107
//~| Min Capture analysis includes:
@@ -127,11 +115,69 @@ fn test_5_should_capture_multi_variant() {
127
115
c ( ) ;
128
116
}
129
117
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
+
130
174
fn main ( ) {
131
175
test_1_should_capture ( ) ;
132
176
test_2_should_not_capture ( ) ;
133
177
test_3_should_not_capture_single_variant ( ) ;
134
178
test_6_should_capture_single_variant ( ) ;
135
179
test_4_should_not_capture_array ( ) ;
136
180
test_5_should_capture_multi_variant ( ) ;
181
+ test_7_should_capture_slice_len ( ) ;
182
+ test_8_capture_slice_wild ( ) ;
137
183
}
0 commit comments